//=============================================================================
/**
 *
 *	@file		phc_diary.c
 *	@brief		PHC日記
 *	@author		hosaka genya
 *	@data		2009.01.29
 *	@note		STRBUF_ADDStrにより、2つのGMMメンバを合成する処理を行っています。
 *				合成するGMMは以下の前提になっています。
 *				・別の文になっている(文節で区切らない)
 *				・合計4行未満
 */
//=============================================================================
#include "common.h"
#include "gflib/touchpanel.h"
#include "system/procsys.h"
#include "system/arc_util.h"
#include "system/arc_tool.h"
#include "system/brightness.h"
#include "system/clact_util.h"
#include "system/clact_tool.h"
#include "system/wipe.h"
#include "system/wordset.h"
#include "system/fontproc.h"
#include "system/msgdata_util.h"
#include "system/snd_tool.h"
#include "system/pm_rtc.h"
#include "system/gra_tool.h"
#include "gflib/strbuf_family.h"
#include "poketool/poke_tool.h"
#include "poketool/pokeicon.h"
#include "itemtool/itemsym.h"
#include "field/pair_poke_idx.h"
//#include "system/touch_subwindow.h"

#include "msgdata/msg.naix"
#include "msgdata/msg_phc_diary.h"
#include "msgdata/msg_monsname.h"

#include "savedata/phc_svdata.h"
#include "savedata/mystatus.h"

#include "application/phc_diary.h"

#include "phc_diary_define.h"
#include "phc_diary_gra.naix"
#include "phcdia_obj_NANR_LBLDEFS.h"
#include "tureicon_obj_NANR_LBLDEFS.h"
#include "data/mmodel/mmodel.naix"

// デバッグ定義
#ifdef PM_DEBUG
	#define PHCD_DEBUG_PRINT　// 上画面にBMPWINでデバッグ情報を表示
#endif

typedef struct PHC_DIARY_tag * PHC_DIARY_PTR;
typedef struct PHCD_POKE_ACT_tag * PHCD_POKE_ACT_PTR;

#define	COL_N_BLACK		( GF_PRINTCOLOR_MAKE( 1, 2, 0 ) )		// フォントカラー：黒

//=============================================================================
/**
 *								定数定義
 */
//=============================================================================
enum
{
	PHC_DIA_HEAP_SIZE = 0x60000,
	FONT_PAL_TALK = 14,
	FONT_PAL_RET = 6,	///< 「もどる」フォント用パレット位置

	PHCD_TR_NAME_SIZE = 8 + EOM_SIZE,
	PHCD_NICKNAME_SIZE = 10 + EOM_SIZE,
	PHCD_COURSE_NAME_SIZE = 10 + EOM_SIZE,
};

enum
{
	CAP_ID_UI_L,		///< ←ボタン
	CAP_ID_UI_R,		///< →ボタン
	CAP_ID_UI_RET,		///< もどるボタン
	CAP_ID_GROUND,		///< 地面
	CAP_ID_L_CMN,		///< 左側汎用
	CAP_ID_R_CMN,		///< 右側汎用
	CAP_ID_L_EFF,		///< 左側エフェクト
	CAP_ID_R_EFF,		///< 右側エフェクト
	CAP_ID_N_EFF,		///< 真ん中エフェクト
	CAP_ID_L_EFF_M,		///< 左側エフェクト(メイン)
	CAP_ID_MAX,
};

enum
{
	POKE_ACT_L = 0,
	POKE_ACT_R,
	POKE_ACT_MAX,
};

typedef enum{
	POKE_DIR_LEFT_STOP,
	POKE_DIR_LEFT,
	POKE_DIR_RIGHT_STOP,
	POKE_DIR_RIGHT,
}POKE_DIR;

typedef enum {
	HERO_DIR_LEFT_STOP,
	HERO_DIR_LEFT,
	HERO_DIR_RIGHT_STOP,
	HERO_DIR_RIGHT,
}HERO_DIR;

enum {
	CAP_POKE_32 = 0,
	CAP_POKE_64,
	CAP_POKE_MAX,
};

//--------------------------------------------------------------
///	ポケモンアクター管理ワーク
//==============================================================
typedef struct PHCD_POKE_ACT_tag {
	BOOL bBigSize;
	int MonsNo;
	CATS_ACT_PTR capPoke[ CAP_POKE_MAX ];
	CATS_ACT_PTR capShadow;
} PHCD_POKE_ACT;

//--------------------------------------------------------------
///	BG 設定
//==============================================================
#define BG_FRM_M_BASE (GF_BGL_FRAME0_M)
#define BG_FRM_M_LAND (GF_BGL_FRAME1_M)
#define BG_FRM_M_TEXT (GF_BGL_FRAME2_M)
#define BG_FRM_S_BASE (GF_BGL_FRAME0_S)
#define BG_FRM_S_TEXT (GF_BGL_FRAME1_S)

#define BG_USE_NUM (5)
static const u8 c_BG_UseList[ BG_USE_NUM ] = {
	BG_FRM_M_BASE,	BG_FRM_M_LAND,	BG_FRM_M_TEXT,
	BG_FRM_S_BASE,	BG_FRM_S_TEXT
};

//--------------------------------------------------------------
///	BMPWIN 設定
//==============================================================
enum
{
	WIN_ID_DATE = 0,
	WIN_ID_HOUR,
	WIN_ID_MSG,
	WIN_ID_RET,
#ifdef PHCD_DEBUG_PRINT
	WIN_ID_S_PAGE_ID,
	WIN_ID_S_ACT_ID,
	WIN_ID_S_MY_POKE_ID,
	WIN_ID_S_MY_POKE_NAME,
	WIN_ID_S_MY_POKE_FORM,
	WIN_ID_S_MY_POKE_SEX,
	WIN_ID_S_MY_STEP_DAY,
	WIN_ID_S_MY_STEP_HOUR,
	WIN_ID_S_EN_POKE_ID,
	WIN_ID_S_EN_POKE_NAME,
	WIN_ID_S_EN_POKE_FORM,
	WIN_ID_S_EN_POKE_SEX,
	WIN_ID_S_EN_STEP_DAY,
	WIN_ID_S_EN_STEP_HOUR,
	WIN_ID_S_ROM_VERSION,
	WIN_ID_S_MSG_1_ID,
	WIN_ID_S_MSG_2_ID,
	WIN_ID_S_ITEM_ID,
#endif
	WIN_ID_MAX,
};

#define BMPSTR_H		(2)
#define BMPSTR_4_H		(BMPSTR_H * 4)
// ++ Width ++
#define WIN_DATE_W		(13)
#define WIN_HOUR_W		(8)
#define WIN_MSG_W		(27)
#define WIN_RET_W		(6)
// ++ CGX ++
#define WIN_DATE_CGX	(1)
#define WIN_HOUR_CGX	(WIN_DATE_CGX + WIN_DATE_W * BMPSTR_H)
#define WIN_MSG_CGX		(WIN_HOUR_CGX + WIN_HOUR_W * BMPSTR_H)
#define WIN_RET_CGX		(WIN_MSG_CGX + WIN_MSG_W * BMPSTR_4_H)

#ifdef PHCD_DEBUG_PRINT
	#define DEBUG_WIN_ID_START ( WIN_ID_S_PAGE_ID )
	#define DEBUG_WIN_ID_MAX ( WIN_ID_MAX - DEBUG_WIN_ID_START )
	#define DEBUG_W (16)
	#define DEBUG_CGX(idx)		(1+idx*(DEBUG_W*BMPSTR_H))
#endif

// ++ bmpwin data table ++
static const BMPWIN_DAT c_BmpWinData[ WIN_ID_MAX ] =
{
	{ BG_FRM_M_TEXT,  2,  1, WIN_DATE_W,	BMPSTR_H,	FONT_PAL_TALK, WIN_DATE_CGX },
	{ BG_FRM_M_TEXT, 22,  1, WIN_HOUR_W,	BMPSTR_H,	FONT_PAL_TALK, WIN_HOUR_CGX },
	{ BG_FRM_M_TEXT,  3, 12, WIN_MSG_W,		BMPSTR_4_H,	FONT_PAL_TALK, WIN_MSG_CGX },
	{ BG_FRM_M_TEXT, 25, 21, WIN_RET_W,		BMPSTR_H,	FONT_PAL_RET, WIN_RET_CGX },
#ifdef PHCD_DEBUG_PRINT
	// debug print
	{ BG_FRM_S_TEXT,  0,  0, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(0) },
	{ BG_FRM_S_TEXT,  0,  2, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(1) },
	{ BG_FRM_S_TEXT,  0,  4, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(2) },
	{ BG_FRM_S_TEXT,  0,  6, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(3) },
	{ BG_FRM_S_TEXT,  0,  8, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(4) },
	{ BG_FRM_S_TEXT,  0, 10, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(5) },
	{ BG_FRM_S_TEXT,  0, 12, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(6) },
	{ BG_FRM_S_TEXT,  0, 14, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(7) },
	{ BG_FRM_S_TEXT,  0, 16, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(8) },
	{ BG_FRM_S_TEXT,  0, 18, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(9) },
	{ BG_FRM_S_TEXT,  0, 20, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(10) },
	{ BG_FRM_S_TEXT,  0, 22, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(11) },
	{ BG_FRM_S_TEXT,  16, 0, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(12) },
	{ BG_FRM_S_TEXT,  16, 2, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(13) },
	{ BG_FRM_S_TEXT,  16, 4, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(14) },
	{ BG_FRM_S_TEXT,  16, 6, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(15) },
	{ BG_FRM_S_TEXT,  16, 8, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(16) },
	{ BG_FRM_S_TEXT,  16, 10, DEBUG_W, BMPSTR_H, FONT_PAL_TALK, DEBUG_CGX(17) },
#endif
};

//=============================================================================
/**
 *								構造体定義
 */
//=============================================================================

//--------------------------------------------------------------
///	メインワーク
//==============================================================
typedef struct PHC_DIARY_tag {
	// [IN]
	const PHC_DIARY_PARAM* inParam;
	HEAPID HeapID;
	const STRCODE* TrName;
	u32 TrSex;
	// [PRIVATE]
	ARCHANDLE* arcGph;
	GF_BGL_INI* bgl;
	GF_BGL_BMPWIN	Win[ WIN_ID_MAX ];
	WORDSET* Word;
	MSGDATA_MANAGER* MsgMan;	///< PHC日記
	MSGDATA_MANAGER* MsgManP;	///< ポケモン名
	MSGDATA_MANAGER* MsgManI;	///< アイテム名
	CATS_SYS_PTR csp;
	CATS_RES_PTR crp;
	CATS_ACT_PTR cap[ CAP_ID_MAX ];
	PHCD_POKE_ACT actPoke[ POKE_ACT_MAX ];
	PHCDiary* pDiary[ PHC_DIA_DATA_MAX ];	///< ソート後のデータ
	RTCDate PageDate;		///< 現在のページの日付情報
	RTCTime PageTime;		///< 現在のページの時間情報
	u8 PokeLoadProc;
	u8 PageID;
	u8 PageMax;
	u8 DowsingLimitID;		///< ダウジング回数がリミットに達したID
	u8 PokeToreLimitID;		///< ポケトレ回数がリミットに達したID
	u8 DowsingCount;		///< ダウジング回数
	u8 PokeToreCount;		///< ポケトレ回数
	u8 CommCount;			///< PHC通信回数
	u32 CourseIDPre : 8;	///< 前回のコースID
	u32 bGetRarePoke : 1;	///< レアポケモン入手フラグ
	u32 bGetRareItem : 1;	///< 配布ポケモン入手フラグ
	u32 bPageLoad : 1;		///< ページ読み込みフラグ
	u32 PageLoadProc : 4;	///< ページ読み込みシーケンサ
	u32 DummyBit : 17;
	// +++ 特殊アニメ：逃げる用 +++
	u32 bAway : 1;
	u32 AwaySeq : 8;
	u32 AwaySubSeq : 7;
	u32 AwayCount : 16;
	// +++ 特殊アニメ：ポケトレ捕獲用 +++
	u32 bPokeGet : 1;
	u32 PokeGetSeq : 7;
	u32 PokeGetCount : 24;
} PHC_DIARY;

//=============================================================================
/**
 *							プロトタイプ宣言
 */
//=============================================================================
// -- ProtoType --
static void VramDispInit( void );
static void SetVramBank( void );
static int GetMonsArcIdx(const int inMonsNo, const u16 inFormNo, const int inSex);
static u32 GetStepDay( u8* StepDay );
static BOOL CheckReturn( PHC_DIARY_PTR ptr );
static BOOL CheckLeft( PHC_DIARY_PTR ptr );
static BOOL CheckRight( PHC_DIARY_PTR ptr );
static u8 GetRare( PHCDiary* pPHCD, BOOL b_mine );
static u8 GetGroundID( PHCDiary* pPHCD );
static s32 SortFunc_Page( void* elem1, void* elem2 );
static void DATA_Setup( PHC_DIARY_PTR ptr );
static void BMPWIN_Init( PHC_DIARY_PTR ptr );
static void BMPWIN_Delete( PHC_DIARY_PTR ptr );
static void BMPWIN_PrintEx( PHC_DIARY_PTR ptr, u32 WinIdx, u32 MsgIdx, u8 OfsX, u32 Font );
static void BMPWIN_Print( PHC_DIARY_PTR ptr, u32 WinIdx, u32 MsgIdx, u8 OfsX );
static void BMPWIN_PrintMsg( PHC_DIARY_PTR ptr, u32 msg1, u32 msg2 );
static void Regist_StrCode( PHC_DIARY_PTR ptr, const STRCODE* code, u8 bufID, u16 strSize );
static void Regist_Item( PHC_DIARY_PTR ptr, u16 ItemNo );
static void Regist_PokeName( PHC_DIARY_PTR ptr, u8 bufID, u16 MonsNo );
static void Regist_Nick( PHC_DIARY_PTR ptr, const STRCODE* code, u8 bufID, u16 MonsNo );
static void Regist_NumberEx( PHC_DIARY_PTR ptr, u8 bufID, u32 num, u8 digi, NUMBER_DISPTYPE dispType );
static void Regist_Number( PHC_DIARY_PTR ptr, u8 bufID, u32 num, u8 digi );
static void PRINT_Flash( PHC_DIARY_PTR ptr, u32 msg1, u32 msg2 );
static void PRINT_Static( PHC_DIARY_PTR ptr );
static void BG_Init( PHC_DIARY_PTR ptr );
static void BG_Delete( PHC_DIARY_PTR ptr );
static void BG_LoadRes( PHC_DIARY_PTR ptr );
static void BG_LoadLandScreen( PHC_DIARY_PTR ptr, u32 hour, u32 GroundID );
static void BGM_Change( PHC_DIARY_PTR ptr, u32 GroundID );
static void OBJ_Init( PHC_DIARY_PTR ptr );
static void OBJ_Delete( PHC_DIARY_PTR ptr );
static void OBJ_LoadRes( PHC_DIARY_PTR ptr );
static CATS_ACT_PTR OBJ_AddMain( CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 pos_x, s16 pos_y, u8 anm, u8 pri );
static CATS_ACT_PTR OBJ_AddMainIcon( CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 pos_x, s16 pos_y, u8 anm, u8 pri );
static void OBJ_Setup( PHC_DIARY_PTR ptr );
static void OBJ_SetEnableEventObj( PHC_DIARY_PTR ptr, BOOL b_enable );
static void OBJ_OneAnime( PHC_DIARY_PTR ptr, u32 capID );
static void OBJ_ChangeGround( PHC_DIARY_PTR ptr, u8 ground_idx );
static void OBJ_CgxChangeTransShiftVramOfs( CLACT_WORK_PTR act, u8 * buf, u32 siz, u32 VramOfs );
static BOOL OBJ_LoadResPokeProc( PHC_DIARY_PTR ptr );
static void PokeAct_SetEnable( PHCD_POKE_ACT_PTR poke_act, BOOL b_enable );
static void PokeAct_SetAnime( PHCD_POKE_ACT_PTR poke_act, u16 aseq );
static void PokeAct_SetPos( PHCD_POKE_ACT_PTR poke_act, s16 pos_x, s16 pos_y, BOOL b_jump );
static void PokeAct_Init( PHC_DIARY_PTR ptr );
static void PokeAct_Delete( PHC_DIARY_PTR ptr );
static void PokeAct_Add( PHCD_POKE_ACT_PTR outAct, CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 pos_x, s16 pos_y, u8 anm, BOOL b_you );
static void PokeAct_TransSetCore( PHCD_POKE_ACT_PTR actPoke, u16 MonsNo, u8 Form, u8 Sex, u8 Rare, HEAPID HeapID );
static void PokeAct_TransPage( PHC_DIARY_PTR ptr, u32 pokeActID, BOOL b_mine );
static void Hero_SetAnime( CATS_ACT_PTR cap, u8 TrSex, HERO_DIR dir );
static void IconAct_SetupByPoke( PHC_DIARY_PTR ptr, u32 pokeActID, u32 capID, u32 aseq );
static void SpecialAnime_Cnt_Proc( PHC_DIARY_PTR ptr );
static void SpecialAnime_Cnt_End( PHC_DIARY_PTR ptr );
static void SpecialAnime_AwayStart( PHC_DIARY_PTR ptr );
static void SpecialAnime_AwayEnd( PHC_DIARY_PTR ptr ) ;
static void SpecialAnime_AwayProc( PHC_DIARY_PTR ptr );
static void SpecialAnime_PokeGetStart( PHC_DIARY_PTR ptr );
static void SpecialAnime_PokeGetEnd( PHC_DIARY_PTR ptr );
static void SpecialAnime_PokeGetProc( PHC_DIARY_PTR ptr );
static void page_phc_comm( PHC_DIARY_PTR ptr );
static void page_dowsing( PHC_DIARY_PTR ptr );
static void page_item_rare( PHC_DIARY_PTR ptr );
static void page_poke_tore( PHC_DIARY_PTR ptr );
static void page_poke_rare( PHC_DIARY_PTR ptr );
static void page_poke_away( PHC_DIARY_PTR ptr );
static void page_poke_lost(PHC_DIARY_PTR ptr );
static void page_ev_item( PHC_DIARY_PTR ptr );
static void page_ev_watt( PHC_DIARY_PTR ptr );
static void page_tureteke( PHC_DIARY_PTR ptr );
static void page_return( PHC_DIARY_PTR ptr );
static void page_act_start( PHC_DIARY_PTR ptr );
static void page_act_end( PHC_DIARY_PTR ptr );
static void page_step( PHC_DIARY_PTR ptr, u32 hour );
static void Page_Load( PHC_DIARY_PTR ptr );
static BOOL Page_LoadProc( PHC_DIARY_PTR ptr );
static void PHC_DIA_Create( PROC* proc );
static void PHC_DIA_Delete( PROC* proc );
static void PHC_DIA_VBlank( void* work );
PROC_RESULT PhcDiaryProc_Init( PROC* proc, int* seq );
PROC_RESULT PhcDiaryProc_End( PROC* proc, int* seq );
PROC_RESULT PhcDiaryProc_Main( PROC* proc, int* seq );


//=============================================================================
/**
 *								static関数
 */
//=============================================================================

//-----------------------------------------------------------------------------
/**
 *	@brief	VramDisp初期化
 *
 *	@param	void
 *
 *	@retval	none
 */
//-----------------------------------------------------------------------------
static void VramDispInit( void )
{
	sys_VBlankFuncChange( NULL, NULL );	// VBlankセット
	sys_HBlankIntrStop();

	GF_Disp_GX_VisibleControlInit();
	GF_Disp_GXS_VisibleControlInit();
	GX_SetVisiblePlane( 0 );
	GXS_SetVisiblePlane( 0 );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	VRAM設定
 *
 *	@param	void
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void SetVramBank( void )
{
	GF_BGL_DISPVRAM tbl = {
		GX_VRAM_BG_64_E,				// メイン2DエンジンのBG
		GX_VRAM_BGEXTPLTT_NONE,			// メイン2DエンジンのBG拡張パレット

		GX_VRAM_SUB_BG_128_C,			// サブ2DエンジンのBG
		GX_VRAM_SUB_BGEXTPLTT_NONE,		// サブ2DエンジンのBG拡張パレット

		GX_VRAM_OBJ_256_AB,				// メイン2DエンジンのOBJ
		GX_VRAM_OBJEXTPLTT_NONE,		// メイン2DエンジンのOBJ拡張パレット

		GX_VRAM_SUB_OBJ_16_I,			// サブ2DエンジンのOBJ
		GX_VRAM_SUB_OBJEXTPLTT_NONE,	// サブ2DエンジンのOBJ拡張パレット

		GX_VRAM_TEX_NONE,				// テクスチャイメージスロット
		GX_VRAM_TEXPLTT_NONE			// テクスチャパレットスロット
	};

	GF_Disp_SetBank( &tbl );
}


//--------------------------------------------------------------
/**
 * 連れ歩きポケモンのアーカイブインデックスを返す
 * @param	inMonsNo	モンスターナンバー
 * @param	inFormNo	フォルムナンバー
 * @param	inSex		性別
 *
 * @retval	idx			アーカイブインデックス
 */
//--------------------------------------------------------------
static int GetMonsArcIdx(const int inMonsNo, const u16 inFormNo, const int inSex)
{
	int idx;
	if ( (inMonsNo<=0) || (MONSNO_END<inMonsNo) ){
		idx = 1;
	}else{
		idx = NARC_mmodel_tsure_001_nsbtx + PairPokeIdx_GetIdx(inMonsNo);
		//モンスターナンバーだけからだと不十分なので、ここからさらに調べる（フォルムとか）
		//性別による描き違いをして、かつ複数フォルムナンバー所持ポケモンはいないので、
		//性別違いをまずキーにして分岐
		if (PairPokeIdx_GetSexDif(inMonsNo)){		//性別による描き違いがある
			if(inSex == PARA_FEMALE ){ //メスの場合
				idx += 1;	//ベースから1シフトしたところがメスのコード
			}
		}else{		//性別による描き違いがない
			//フォルムを調べる
			int form;
			if ( inFormNo > PairPokeIdx_GetFormNum(inMonsNo) ){
				form = 0;
			}else{
				form = inFormNo;
			}
			idx += form;
		}
	}
	return idx;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	一日の歩数データアクセス関数
 *
 *	@param	u8* StepDay
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u32 GetStepDay( u8* StepDay )
{
//	HOSAKA_PRINT("step[]= %d %d %d\n", StepDay[2], StepDay[1], StepDay[0] );
	return (StepDay[2]<<16) + (StepDay[1]<<8) + StepDay[0];
}

//-----------------------------------------------------------------------------
/**
 *	@brief	終了チェック
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static BOOL CheckReturn( PHC_DIARY_PTR ptr )
{
	// もどるボタン
	const TP_HIT_TBL hit_tbl = { OBJ_RET_Y-2*8, OBJ_RET_Y+2*8, OBJ_RET_X-4*8, OBJ_RET_X+4*8 };

	if( GF_TP_SingleHitTrg( &hit_tbl ) || ( sys.trg & PAD_BUTTON_CANCEL ) )
	{
		Snd_SePlay( SEQ_SE_DP_SELECT );
		CATS_ObjectAnimeReStartCap( ptr->cap[ CAP_ID_UI_RET ] );
		return TRUE;
	}

	return FALSE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	左ページ切替判定
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static BOOL CheckLeft( PHC_DIARY_PTR ptr )
{
	if( ptr->PageID > 0 )
	{
		// 左ボタン
		const TP_HIT_TBL hit_tbl = { OBJ_UI_L_Y-2*8, OBJ_UI_L_Y+2*8, OBJ_UI_L_X-2*8, OBJ_UI_L_X+2*8 };

		if( GF_TP_SingleHitTrg( &hit_tbl ) || ( sys.trg & PAD_KEY_LEFT ) )
		{
			return TRUE;
		}
	}

	return FALSE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	右ページ切替判定
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static BOOL CheckRight( PHC_DIARY_PTR ptr )
{
	if( ptr->PageID < ptr->PageMax -1 )
	{
		// 右ボタン
		const TP_HIT_TBL hit_tbl = { OBJ_UI_R_Y-2*8, OBJ_UI_R_Y+2*8, OBJ_UI_R_X-2*8, OBJ_UI_R_X+2*8 };

		if( GF_TP_SingleHitTrg( &hit_tbl ) || ( sys.trg & PAD_KEY_RIGHT ) )
		{
			return TRUE;
		}
	}

	return FALSE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	レアカラーフラグ取得
 *
 *	@param	PHCDiary* pPHCD
 *	@param	b_mine
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u8 GetRare( PHCDiary* pPHCD, BOOL b_mine )
{
	return (b_mine) ? pPHCD->myRareColor : pPHCD->yourRareColor;
}

//-----------------------------------------------------------------------------
/**
 *	@brief
 *
 *	@param	PHCDiary* pPHCD
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u8 GetGroundID( PHCDiary* pPHCD )
{
	int ret;

	// MAXよりでかかったら絶対野原(壊れデータ対策)
	if( pPHCD->courseId >= CRS_ID_MAX )
	{
#ifdef PM_DEBUG
		GF_ASSERT(0);
#endif
		ret = CRS_ID_GRASS;
	}
	else
	{
		// コースID = 背景ID
		ret = pPHCD->courseId;
	}

	return ret;
}


//--------------------------------------------------------------
///	ソート用データ
//==============================================================
typedef struct {
	PHCDiary* pDiary;
	int default_id;
} PHCD_SORT_DATA;

//-----------------------------------------------------------------------------
/**
 *	@brief	クイックソート用関数 時間を基準に並べなおす
 *
 *	@param	void* elem1
 *	@param	elem2
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static s32 SortFunc_Page( void* elem1, void* elem2 )
{
	PHCD_SORT_DATA* p1 = (PHCD_SORT_DATA*)elem1;
	PHCD_SORT_DATA* p2 = (PHCD_SORT_DATA*)elem2;

	if( p1->pDiary->rtcSecond == p2->pDiary->rtcSecond )
	{
		return 0;
	}
	// でかいほうを後ろに積む
	else if( p1->pDiary->rtcSecond > p2->pDiary->rtcSecond )
	{
		return 1;
	}
	else
	{
		return -1;
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	データ取得・生成
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void DATA_Setup( PHC_DIARY_PTR ptr )
{
	int i;
	PHC_SVDATA* phcsv;
	const MYSTATUS* myst;
	PHCD_SORT_DATA sort[ PHC_DIA_DATA_MAX ] = {0};
	u32 rtcSecondMin = 0xffffffff;		// 一番若いRTC

	GF_ASSERT(ptr);
	GF_ASSERT(ptr->inParam);

	phcsv = SaveData_GetPhcSaveData( ptr->inParam->pSaveData );
	myst = SaveData_GetMyStatus( ptr->inParam->pSaveData );

	// トレーナー情報を取得
	ptr->TrSex = MyStatus_GetMySex( myst );
	ptr->TrName = MyStatus_GetMyName( myst );

	OS_TPrintf("\n***** PhcDiary::MakePage *****\n\n", ptr->PageMax);

	// ページ数計算
	for( i=0; i<PHC_DIA_DATA_MAX; i++ )
	{
		PHCDiary* inPHCD;
		int actionId;

		inPHCD = &ptr->inParam->pDiaryData[i];

		// 金銀VERの場合
		if( inPHCD->romVersion == VERSION_GOLD || inPHCD->romVersion == VERSION_SILVER )
		{
			// 金銀で出現する範囲のポケモンNOか破損チェック
			if( inPHCD->pokeNumber > MONSNO_END || inPHCD->enemyNumber > MONSNO_END )
			{
				continue;
			}
		}

		// @@@ 破損チェックを増やすならここ

		// PHC側のアクションIDをPHC日記用のアクションIDに変更
		switch( inPHCD->actionId )
		{
			case ACT_ID_ITEM_RARE :
				inPHCD->actionId = ACT_ID_DOWSING;
				break;
			case ACT_ID_POKE_RARE :
				inPHCD->actionId = ACT_ID_POKETORE;
				break;
			case ACT_ID_SHARE_ITEM :
				inPHCD->actionId = ACT_ID_ITEM_RARE;
				break;
			case ACT_ID_SHARE_POKE :
				inPHCD->actionId = ACT_ID_POKE_RARE;
				break;
			default :
				; // 処理なし
		}

		actionId = inPHCD->actionId;

		// アクションIDの範囲がおかしければページ無効
		if( actionId >= ACT_ID_APP_MAX )
		{
			actionId = ACT_ID_NULL;
		}
		// 通信回数を保存
		else if( actionId >= ACT_ID_COMM_IN && actionId <= ACT_ID_COMM_END )
		{
			ptr->CommCount++;
		}
		// レアアイテムフラグをたてる
		else if( actionId == ACT_ID_ITEM_RARE )
		{
			ptr->bGetRareItem = TRUE;
		}
		// レアポケモンフラグを立てる
		else if( actionId == ACT_ID_POKE_RARE )
		{
			ptr->bGetRarePoke = TRUE;
		}
		// ダウジングIDの回数が限度を超えたIDを保存
		else if( actionId == ACT_ID_DOWSING )
		{
			if( ptr->DowsingLimitID == 0 )
			{
				ptr->DowsingCount++;
				if( ptr->DowsingCount >= DOWSING_LIMIT )
				{
					ptr->DowsingLimitID = i;
					HOSAKA_PRINT( "DowsingLimitID:%d\n",i );
				}
			}
		}
		// ポケトレIDの回数が限度を超えたIDを保存
		else if( actionId == ACT_ID_POKETORE )
		{
			if( ptr->PokeToreLimitID == 0 )
			{
				ptr->PokeToreCount++;
				if( ptr->PokeToreCount >= POKETORE_LIMIT )
				{
					ptr->PokeToreLimitID = i;
					HOSAKA_PRINT( "PokeToreLimitID:%d\n",i );
				}
			}
		}

		// ページ数を集計
		if( actionId != ACT_ID_NULL )
		{
			GF_ASSERT( inPHCD->actionId != ACT_ID_NULL );

			// 一番若いRTCを保持
			if( rtcSecondMin > inPHCD->rtcSecond )
			{
				rtcSecondMin = inPHCD->rtcSecond;
			}

			// 有効ページを保持
			sort[ ptr->PageMax ].pDiary = inPHCD;
			sort[ ptr->PageMax ].default_id = i;

			ptr->PageMax++;
		}
	}

	HOSAKA_PRINT("PageMax:%d\n", ptr->PageMax);

#ifdef PM_DEBUG
	OS_TPrintf("▼pre sort \n");
	// 情報表示
	for( i=0; i<ptr->PageMax; i++ )
	{
		PHCDiary* pDiary = sort[i].pDiary;
		OS_TPrintf("================================================> Page:%d \n", i);
		OS_TPrintf("addr:%p default_id:%d actionId:%d \n", pDiary, sort[i].default_id, pDiary->actionId );
		OS_TPrintf(
			"RtcSecond :%d, country:%d romVersion:%d pokeNumber:%d enemyNumber:%d itemNumber:%d \n",
			pDiary->rtcSecond, pDiary->country, pDiary->romVersion, pDiary->pokeNumber, pDiary->enemyNumber, pDiary->itemNumber
		);

		OS_TPrintf(
			"myStepHour:%d yourStepHour:%d courseId:%d friendly:%d \n",
			pDiary->myStepHour, pDiary->yourStepHour, pDiary->courseId, pDiary->friendly );
	}
#endif

	// 「冒険開始」のRTCが一番若くなければ強制的に若くする
	OS_TPrintf("rtcSecondMin : %u \n", rtcSecondMin );
	for( i=0; i<ptr->PageMax; i++ )
	{
		if( sort[i].pDiary->actionId == ACT_ID_ACT_START )
		{
			OS_TPrintf("act start rtcSecond : %u \n", sort[i].pDiary->rtcSecond );
			if(	sort[i].pDiary->rtcSecond > rtcSecondMin )
			{
				GF_ASSERT( rtcSecondMin > 0 );
				sort[i].pDiary->rtcSecond = (rtcSecondMin - 1);
				OS_TPrintf("hook start page rtcSecond \n");
			}
			break;
		}
	}

	// クイックソート
	MATH_QSort( (void*)sort, ptr->PageMax, sizeof(PHCD_SORT_DATA), SortFunc_Page, NULL );

	if(ptr->PageMax < 2 )
	{
		// 必ず2ページ以上はある前提
#ifdef PM_DEBUG
		GF_ASSERT(0);
#endif
		// グランドIDを設定
//		ptr->pDiary[ ptr->PageMax-1 ]->courseId = 0;
		sort[ ptr->PageMax-1 ].pDiary->courseId = 0;
		// 時間を設定
//		ptr->pDiary[ ptr->PageMax-1 ]->rtcSecond = GF_RTC_GetDateTimeBySecond();
		sort[ ptr->PageMax-1 ].pDiary->rtcSecond = GF_RTC_GetDateTimeBySecond();
	}
	else
	{
		//------------------------------------------------------
		// 終端ページ：１つ前のページから値を設定
		//------------------------------------------------------
		const PHCDiary* p_src = sort[ ptr->PageMax-2 ].pDiary;

		// グランドIDを設定
		sort[ ptr->PageMax-1 ].pDiary->courseId = p_src->courseId;

		// 時間を設定
		if( p_src->actionId == ACT_ID_STEP )
		{
			// 歩数日記だった場合は1時間進める
			sort[ ptr->PageMax-1 ].pDiary->rtcSecond = p_src->rtcSecond + 60 * 60 * 1;
		}
		else
		{
			// 0秒で通信はできないので、5秒たったことにしておく。
			sort[ ptr->PageMax-1 ].pDiary->rtcSecond = p_src->rtcSecond + 5;
		}
	}

	// ACT_ID_STEPで300未満が続いた場合はスキップ
	{
		int actionId_old = ACT_ID_NULL;
		int step_hour_old = 0;

		for( i=0; i<ptr->PageMax; i++ )
		{
			int actionId;
			int step_hour;

			actionId = sort[i].pDiary->actionId;
			step_hour = sort[i].pDiary->myStepHour;

			if( actionId == ACT_ID_STEP && actionId_old == ACT_ID_STEP && step_hour < 300 && step_hour_old < 300 )
			{
				// ページデータを無効化
				sort[i].pDiary->actionId = ACT_ID_NULL;
			}

			// 前回のアクションIDを保持
			actionId_old = actionId;
			step_hour_old = step_hour;
		}
	}

	OS_TPrintf("歩数ページ圧縮前 PAGE MAX=%d \n", ptr->PageMax);

	{
		int cnt = 0;

		// データ保持
		for( i=0; i < ptr->PageMax; i++ )
		{
			// 有効ページのみ
			if( sort[i].pDiary->actionId != ACT_ID_NULL )
			{
				ptr->pDiary[cnt] = sort[i].pDiary;
				cnt++;
			}
		}

		ptr->PageMax = cnt;

		OS_TPrintf("歩数ページ圧縮後 PAGE MAX=%d \n", ptr->PageMax);
	}

#ifdef PM_DEBUG
	OS_TPrintf("\n\n▼sorted \n");

	// 情報表示
	for( i=0; i<ptr->PageMax; i++ )
	{
		PHCDiary* pDiary = ptr->pDiary[i];
		OS_TPrintf("================================================> Page:%d \n", i);
		OS_TPrintf("addr:%p actionId:%d \n", pDiary, pDiary->actionId );
		OS_TPrintf(
			"RtcSecond :%d, country:%d romVersion:%d pokeNumber:%d enemyNumber:%d itemNumber:%d \n",
			pDiary->rtcSecond, pDiary->country, pDiary->romVersion, pDiary->pokeNumber, pDiary->enemyNumber, pDiary->itemNumber
		);

		OS_TPrintf(
			"myStepHour:%d yourStepHour:%d courseId:%d friendly:%d \n",
			pDiary->myStepHour, pDiary->yourStepHour, pDiary->courseId, pDiary->friendly );
	}
#endif

}

//-----------------------------------------------------------------------------
/**
 *	@brief	BMPWIN関連初期化
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BMPWIN_Init( PHC_DIARY_PTR ptr )
{
	int i;

	GF_ASSERT(ptr);
	GF_ASSERT(ptr->bgl);

	ptr->MsgMan = MSGMAN_Create( MSGMAN_TYPE_DIRECT, ARC_MSG, NARC_msg_phc_diary_dat, ptr->HeapID );
	ptr->MsgManP = MSGMAN_Create( MSGMAN_TYPE_DIRECT, ARC_MSG, NARC_msg_monsname_dat, ptr->HeapID );
	ptr->MsgManI = MSGMAN_Create( MSGMAN_TYPE_DIRECT, ARC_MSG, NARC_msg_itemname_dat, ptr->HeapID );
	ptr->Word = WORDSET_CreateEx( MSGBUF_MAX, WORDSET_DEFAULT_BUFLEN, ptr->HeapID );

	for(i=0; i<WIN_ID_MAX; i++ )
	{
		const BMPWIN_DAT* dat = &c_BmpWinData[i];
		GF_BGL_BmpWinAddEx( ptr->bgl, &(ptr->Win[i]), dat );
	}

	//先頭キャラをクリア（スクリーンクリアされてるところは、このキャラで埋まる）
	GF_BGL_CharFill( ptr->bgl, BG_FRM_M_TEXT, 0, 1, 0 );

	// トークフォントパレット転送
	TalkFontPaletteLoad( PALTYPE_MAIN_BG, 0x20 * FONT_PAL_TALK, ptr->HeapID );
	TalkFontPaletteLoad( PALTYPE_SUB_BG, 0x20 * FONT_PAL_TALK, ptr->HeapID );

	// タッチフォントロード
	FontProc_LoadFont( FONT_TOUCH, ptr->HeapID );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	BMPWIN関連削除
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BMPWIN_Delete( PHC_DIARY_PTR ptr )
{
	int i;

	for( i=0; i<WIN_ID_MAX; i++ )
	{
		GF_BGL_BmpWinDel( &ptr->Win[i] );
	}

	WORDSET_Delete( ptr->Word );
	MSGMAN_Delete( ptr->MsgMan );
	MSGMAN_Delete( ptr->MsgManP );
	MSGMAN_Delete( ptr->MsgManI );

	FontProc_UnloadFont( FONT_TOUCH );

}

//-----------------------------------------------------------------------------
/**
 *	@brief	文字列を描画(フォント指定)
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	WinIdx
 *	@param	MsgIdx
 *	@param	OfsX
 *	@param	Font
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BMPWIN_PrintEx( PHC_DIARY_PTR ptr, u32 WinIdx, u32 MsgIdx, u8 OfsX, u32 Font )
{
	STRBUF* strbuf;
	GF_BGL_BMPWIN* Win;

	GF_ASSERT( WinIdx < WIN_ID_MAX );

	Win = &ptr->Win[ WinIdx ];

	GF_BGL_BmpWinDataFill( Win, 0 );

	strbuf = MSGDAT_UTIL_AllocExpandString( ptr->Word, ptr->MsgMan, MsgIdx, ptr->HeapID );

	GF_STR_PrintColor( Win, Font, strbuf, OfsX, 0, MSG_NO_PUT, COL_N_BLACK, NULL );

	STRBUF_Delete( strbuf );

	GF_BGL_BmpWinOn( Win );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	文字を描画
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	WinIdx
 *	@param	MsgIdx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BMPWIN_Print( PHC_DIARY_PTR ptr, u32 WinIdx, u32 MsgIdx, u8 OfsX )
{
	BMPWIN_PrintEx( ptr, WinIdx, MsgIdx, OfsX, FONT_TALK );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	日記メッセージ:２つのメッセージを連結して表示
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	msg1
 *	@param	msg2
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BMPWIN_PrintMsg( PHC_DIARY_PTR ptr, u32 msg1, u32 msg2 )
{
	STRBUF* str1;
	STRBUF* str2;
	STRBUF* total_buf;
	GF_BGL_BMPWIN* Win;

	Win = &ptr->Win[ WIN_ID_MSG ];

	// データクリア
	GF_BGL_BmpWinDataFill( Win, 0 );

	str1 = MSGDAT_UTIL_AllocExpandString( ptr->Word, ptr->MsgMan, msg1, ptr->HeapID );

	if( msg2 != NULL )
	{
		str2 = MSGDAT_UTIL_AllocExpandString( ptr->Word, ptr->MsgMan, msg2, ptr->HeapID );

		// ２つのメッセージの長さ＋改行コード分のSTRBUFを作成
		total_buf = STRBUF_Create( STRBUF_GetLen( str1 ) + STRBUF_GetLen( str2 ) + 2, ptr->HeapID );
		// 文字列連結
		STRBUF_Copy( total_buf, str1 );
		// 改行コード追加
		STRBUF_AddChar( total_buf, CR_ );
		// 文字列連結
		STRBUF_AddStr( total_buf, str2 );

		// 表示
		GF_STR_PrintColor( Win, FONT_TALK, total_buf, 0, 0, MSG_NO_PUT, COL_N_BLACK, NULL );

		// バッファ開放
		STRBUF_Delete( str2 );
		STRBUF_Delete( total_buf );
	}
	else
	{
		// 表示
		GF_STR_PrintColor( Win, FONT_TALK, str1, 0, 0, MSG_NO_PUT, COL_N_BLACK, NULL );
	}

	// バッファ開放
	STRBUF_Delete( str1 );

	GF_BGL_BmpWinOn( Win );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	STRCODEを指定レジスタにレジスト
 *
 *	@param	ptr
 *	@param	const STRCODE* code
 *	@param	bufID
 *	@param	strSize
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void Regist_StrCode( PHC_DIARY_PTR ptr, const STRCODE* code, u8 bufID, u16 strSize )
{
	int i;
	BOOL bNullData;
	STRBUF* buff;

	bNullData = TRUE;
	buff = STRBUF_Create( strSize, ptr->HeapID );

//	OS_TPrintf("strcode = ");
	if( code[0] != NULL )
	{
		// 終端を検索。終端コードがなければダミー文字列を表示
		for( i=0; i<strSize; i++ )
		{
//			OS_TPrintf("0x%x ",(u16)(code[i]));
			if( (u16)(code[i]) == EOM_ )
			{
				bNullData = FALSE;
				break;
			}
		}
	}
//	OS_TPrintf("\n");

	// 空だったらダミーデータを入力
	if( bNullData )
	{
		static const STRCODE dummyCode[] = { ka_, ri_, EOM_ };
		STRBUF_SetStringCode( buff, dummyCode );
	}
	else
	{
		// データがあった場合は直接変換
		STRBUF_SetStringCode( buff, code );
	}

	WORDSET_RegisterWord( ptr->Word, bufID, buff, PM_NEUTRAL, TRUE, PM_LANG );
	STRBUF_Delete( buff );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	アイテム名をレジスト
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	ItemNo
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void Regist_Item( PHC_DIARY_PTR ptr, u16 ItemNo )
{
	STRBUF* buff;
	STRCODE codebuf[ ITEM_NAME_SIZE + EOM_SIZE ];
	u16 len;

	// データ破壊対策
	if( ItemNo > ITEM_DATA_MAX ){ ItemNo = ITEM_DATA_MAX; }

	buff  = MSGMAN_AllocString( ptr->MsgManI, ItemNo );
	len = STRBUF_GetLen(buff) + 1;
	STRBUF_GetStringCode( buff, codebuf, len );
	Regist_StrCode( ptr, codebuf, MSGBUF_ITEM, len );

	STRBUF_Delete( buff );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケモンの種族名をレジスト
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	bufID
 *	@param	MonsNo
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void Regist_PokeName( PHC_DIARY_PTR ptr, u8 bufID, u16 MonsNo )
{
	STRBUF* buff;
	STRCODE codebuf[ PHCD_NICKNAME_SIZE ];
	u16 len;

	buff  = MSGMAN_AllocString( ptr->MsgManP, MonsNo );
	len = STRBUF_GetLen(buff) + 1;
	STRBUF_GetStringCode( buff, codebuf, len );
	Regist_StrCode( ptr, codebuf, bufID, len );

	STRBUF_Delete( buff );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケモンのニックネームをレジスト(NULLの場合は種族名をレジスト)
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	STRCODE* code
 *	@param	bufID
 *	@param	MonsNo
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void Regist_Nick( PHC_DIARY_PTR ptr, const STRCODE* code, u8 bufID, u16 MonsNo )
{
	int i;
	BOOL bNullData = TRUE;

//	OS_TPrintf("PokeName = ");
	if( code[0] != NULL )
	{
		// 終端を検索。終端コードがなければ種族名を表示
		for( i=0; i<(PHCD_NICKNAME_SIZE); i++ )
		{
//			OS_TPrintf("0x%x ",(u16)(code[i]));
			if( (u16)(code[i]) == EOM_ )
			{
				bNullData = FALSE;
				break;
			}
		}
	}
//	OS_TPrintf("\n");

	if( bNullData )
	{
		// 無効データの場合は種族名
		Regist_PokeName( ptr, bufID, MonsNo );
	}
	else
	{
		// ニックネームが存在するときは、そのまま表示
		Regist_StrCode( ptr, code, bufID, PHCD_NICKNAME_SIZE );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	数値をレジスト(表示方式指定版)
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	bufID
 *	@param	num
 *	@param	digi
 *	@param	dispType
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void Regist_NumberEx( PHC_DIARY_PTR ptr, u8 bufID, u32 num, u8 digi, NUMBER_DISPTYPE dispType )
{
	WORDSET_RegisterNumber( ptr->Word, bufID, num, digi, dispType, NUMBER_CODETYPE_DEFAULT );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	数値をレジスト
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	bufID
 *	@param	num
 *	@param	digi
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void Regist_Number( PHC_DIARY_PTR ptr, u8 bufID, u32 num, u8 digi )
{
	Regist_NumberEx( ptr, bufID, num, digi, NUMBER_DISPTYPE_SPACE );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	現在のページの日時・時間を計算・保持
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void Page_CalcDate( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	RTCDate rtc_diposit_Date = {0};
	RTCTime rtc_time_dmy = {0};
	s64 second;

#if 0
	// 預けた日をRTCデータに変換
	GFDate2RTCDate( ptr->DepositDate, &rtc_diposit_Date );
	// 秒に変換
	second = RTC_ConvertDateTimeToSecond( &rtc_diposit_Date, &rtc_time_dmy );
	// このページの経過分を加算
	second += pPHCD->rtcSecond;
#endif
	second = pPHCD->rtcSecond;

	// 最終的な時刻データを取得
	RTC_ConvertSecondToDateTime( &ptr->PageDate, &ptr->PageTime, second );

	HOSAKA_PRINT(
			"month:%d data:%d hour:%d minute:%d second:%d \n",
			ptr->PageDate.month,
			ptr->PageDate.day,
			ptr->PageTime.hour,
			ptr->PageTime.minute,
			ptr->PageTime.second );
}

#ifdef PHCD_DEBUG_PRINT
static void Debug_Print( PHC_DIARY_PTR ptr, PHCDiary* pPHCD, int msg1, int msg2 )
{
	int i;

	// クリア
	GF_BGL_ScrClear( ptr->bgl, BG_FRM_S_TEXT );

	for( i=0; i<DEBUG_WIN_ID_MAX; i++ )
	{
		STRBUF* strbuf;
		int win_idx = DEBUG_WIN_ID_START + i;
		GF_BGL_BMPWIN* win = &ptr->Win[ win_idx ];

		// データクリア
		GF_BGL_BmpWinDataFill( win, 0 );

		switch( win_idx )
		{
			case WIN_ID_S_PAGE_ID :
				{
					static const STRCODE dummyCode[] = { p__, a__, g__, e__, I__, D__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 8 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, ptr->PageID, 2, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_ACT_ID :
				{
					static const STRCODE dummyCode[] = { a__, c__, t__, I__, D__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 8 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->actionId, 2, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_MY_POKE_ID :
				{
					static const STRCODE dummyCode[] = { PO_, KE_, I__, D__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->pokeNumber, 3, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_MY_POKE_NAME :
				{
					static const STRCODE dummyCode[] = { PO_, KE_, N__, I__, C__, K__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_Nick( ptr, (const STRCODE*)pPHCD->myNickname, MSGBUF_DEBUG_2, pPHCD->pokeNumber );
				}
				break;
			case WIN_ID_S_MY_POKE_FORM :
				{
					static const STRCODE dummyCode[] = { PO_, KE_, f__, o__, r__, m__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->myFolm, 2, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_MY_POKE_SEX :
				{
					static const STRCODE dummyCode[] = { PO_, KE_, s__, e__, x__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->mySex, 2, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_MY_STEP_DAY :
				{
					static const STRCODE dummyCode[] = { ho_, su_, u_, D__, A__, Y__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->myStepDay, 6, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_MY_STEP_HOUR :
				{
					static const STRCODE dummyCode[] = { ho_, su_, u_, H__, O__, U__, R__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->myStepHour, 5, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_EN_POKE_ID :
				{
					static const STRCODE dummyCode[] = { te_, ki_, PO_, KE_, I__, D__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->enemyNumber, 3, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_EN_POKE_NAME :
				{
					static const STRCODE dummyCode[] = { te_, ki_, PO_, KE_, N__, I__, C__, K__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_Nick( ptr, (const STRCODE*)pPHCD->enemyNickname, MSGBUF_DEBUG_2, pPHCD->enemyNumber );
				}
				break;
			case WIN_ID_S_EN_POKE_FORM :
				{
					static const STRCODE dummyCode[] = { te_, ki_, PO_, KE_, f__, o__, r__, m__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->yourFolm, 2, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_EN_POKE_SEX :
				{
					static const STRCODE dummyCode[] = { te_, ki_, PO_, KE_, s__, e__, x__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->yourSex, 2, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_EN_STEP_DAY :
				{
					static const STRCODE dummyCode[] = { te_, ki_, ho_, su_, u_, D__, A__, Y__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->yourStepDay, 6, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_EN_STEP_HOUR :
				{
					static const STRCODE dummyCode[] = { te_, ki_, ho_, su_, u_, H__, O__, U__, R__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->yourStepHour, 5, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_ROM_VERSION :
				{
					static const STRCODE dummyCode[] = { R__, o__, m__, V__, e__, r__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->romVersion, 3, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_MSG_1_ID :
				{
					static const STRCODE dummyCode[] = {  TE_, KI_, SU_, TO_, h_n1_, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, msg1, 3, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_MSG_2_ID :
				{
					static const STRCODE dummyCode[] = {  TE_, KI_, SU_, TO_, h_n2_, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, msg2, 3, NUMBER_DISPTYPE_LEFT );
				}
				break;
			case WIN_ID_S_ITEM_ID :
				{
					static const STRCODE dummyCode[] = { A_, I_, TE_, MU_, I__, D__, EOM_ };
					Regist_StrCode( ptr, dummyCode, MSGBUF_DEBUG_1, 16 );
					Regist_NumberEx( ptr, MSGBUF_DEBUG_2, pPHCD->itemNumber, 3, NUMBER_DISPTYPE_LEFT );
				}
				break;

			default : GF_ASSERT(0);
		}

		// デバッグ用GMM登録
		strbuf = MSGDAT_UTIL_AllocExpandString( ptr->Word, ptr->MsgMan, msg_diary_debug_00, ptr->HeapID );

		GF_STR_PrintColor( win, FONT_SYSTEM, strbuf, 0, 0, MSG_NO_PUT, COL_N_BLACK, NULL );
		GF_BGL_BmpWinOn( win );

		STRBUF_Delete( strbuf );
	}
}
#endif // PHCD_DEBUG_PRINT

//-----------------------------------------------------------------------------
/*
 *	@brief	ページ毎の情報をプリント
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	msg1
 *	@param	msg2
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PRINT_Flash( PHC_DIARY_PTR ptr, u32 msg1, u32 msg2 )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	int month;
	int date;
	int hour;
	int hour_msg;

	month = ptr->PageDate.month;
	date = ptr->PageDate.day;
	hour = ptr->PageTime.hour;

	HOSAKA_PRINT("msg1:%d msg2:%d \n", msg1, msg2 );

	// AM/PM判定
	if( hour < 12 )
		{ hour_msg = msg_diary_act_hour_am; }
	else
		{ hour_msg = msg_diary_act_hour_pm; hour -= 12; }

	//---------------------------------------
	// レジスト
	//---------------------------------------
	// 自分のトレーナー名
	Regist_StrCode( ptr, ptr->TrName, MSGBUF_MY_TRAINER, PHCD_TR_NAME_SIZE );
	// 自分のポケ、ニックネーム
	Regist_Nick( ptr, (const STRCODE*)pPHCD->myNickname, MSGBUF_MY_NICK, pPHCD->pokeNumber );
	// 相手のトレーナー名
	Regist_StrCode( ptr, (const STRCODE*)pPHCD->trainerName, MSGBUF_YOUR_TRAINER, PHCD_TR_NAME_SIZE );
	// 相手のポケ、ニックネーム
	Regist_Nick( ptr, (const STRCODE*)pPHCD->enemyNickname, MSGBUF_YOUR_NICK, pPHCD->enemyNumber );
	// アイテム
	Regist_Item( ptr, pPHCD->itemNumber );
	// 捕まえたポケモン(相手のニックネーム)
	Regist_Nick( ptr, (const STRCODE*)pPHCD->enemyNickname, MSGBUF_GET_POKE, pPHCD->enemyNumber );
	// 時間
	Regist_NumberEx( ptr, MSGBUF_HOUR, hour, 2, NUMBER_DISPTYPE_LEFT );
	// 歩数
	Regist_NumberEx( ptr, MSGBUF_STEP, pPHCD->myStepHour, 5, NUMBER_DISPTYPE_LEFT );
	// コースネーム
	Regist_StrCode( ptr, (const STRCODE*)pPHCD->courseNameString, MSGBUF_COURSE, PHCD_COURSE_NAME_SIZE );
	// 月
	Regist_NumberEx( ptr, MSGBUF_MONTH, month, 2, NUMBER_DISPTYPE_LEFT );
	// 日
	Regist_NumberEx( ptr, MSGBUF_DATE, date, 2, NUMBER_DISPTYPE_LEFT );

	// メッセージ表示
	BMPWIN_PrintMsg( ptr, msg1, msg2 );

	// 日時表示
	Regist_NumberEx( ptr, MSGBUF_MONTH, month, 2, NUMBER_DISPTYPE_SPACE );
	Regist_NumberEx( ptr, MSGBUF_DATE, date, 2, NUMBER_DISPTYPE_SPACE );
	BMPWIN_Print( ptr, WIN_ID_DATE, msg_diary_deposit_date, 0 );

	// 行動時間表示
	Regist_NumberEx( ptr, MSGBUF_HOUR, hour, 2, NUMBER_DISPTYPE_SPACE );
	BMPWIN_Print( ptr, WIN_ID_HOUR, hour_msg, 0 );

#ifdef PHCD_DEBUG_PRINT
	Debug_Print( ptr, pPHCD, msg1, msg2 );
#endif

}

//-----------------------------------------------------------------------------
/**
 *	@brief	一度プリントすれば良いフォントを描画
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PRINT_Static( PHC_DIARY_PTR ptr )
{
	// もどるボタンを表示
	BMPWIN_PrintEx( ptr, WIN_ID_RET, msg_d_end_button_cap, 4, FONT_TOUCH );
}
//-----------------------------------------------------------------------------
/**
 *	@brief	BG生成
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_Init( PHC_DIARY_PTR ptr )
{
	ptr->bgl = GF_BGL_BglIniAlloc( ptr->HeapID );

	{	//BG SYSTEM
		GF_BGL_SYS_HEADER BGsys_data = {
			GX_DISPMODE_GRAPHICS,GX_BGMODE_0,GX_BGMODE_0,GX_BG0_AS_2D
		};
		GF_BGL_InitBG(&BGsys_data);
	}

	{
		int i;
		GF_BGL_BGCNT_HEADER TextBgCntDat[ BG_USE_NUM ] = {
			// -- MAIN --
			{	// BG_FRM_M_BASE BG0
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x0000,GX_BG_CHARBASE_0x04000,GX_BG_EXTPLTT_01,
				3,0,0,FALSE
			},
			{	// BG_FRM_M_LAND BG1
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x0800,GX_BG_CHARBASE_0x08000,GX_BG_EXTPLTT_01,
				2,0,0,FALSE
			},
			{	// BG_FRM_M_TEXT BG2
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x1000,GX_BG_CHARBASE_0x0c000,GX_BG_EXTPLTT_01,
				1,0,0,FALSE
			},
			// -- SUB --
			{	// BG_FRM_S_BASE BG0
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x0000,GX_BG_CHARBASE_0x04000,GX_BG_EXTPLTT_01,
				3,0,0,FALSE
			},
			{	// BG_FRM_S_TEXT BG1
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0x0800,GX_BG_CHARBASE_0x08000,GX_BG_EXTPLTT_01,
				0,0,0,FALSE
			},
		};

		for(i = 0;i < BG_USE_NUM;i++){
			GF_BGL_BGControlSet( ptr->bgl, c_BG_UseList[i], &(TextBgCntDat[i]), GF_BGL_MODE_TEXT );
			GF_BGL_ScrClear( ptr->bgl, c_BG_UseList[i] );
			GF_BGL_CharFill( ptr->bgl, c_BG_UseList[i], 0, 1, 0 );
		}
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	BG開放
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_Delete( PHC_DIARY_PTR ptr )
{
	int i;

	for( i=0; i<BG_USE_NUM; i++ )
	{
		GF_BGL_BGControlExit( ptr->bgl, c_BG_UseList[i] );
	}

	sys_FreeMemoryEz( ptr->bgl );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	BGリソースロード
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_LoadRes( PHC_DIARY_PTR ptr )
{
	GF_ASSERT(ptr->bgl);

	//=====================================================
	// Main LCD
	//=====================================================
	// -- pal --
	ArcUtil_HDL_PalSet( ptr->arcGph, NARC_phc_diary_gra_phcdia_bg_NCLR,
			PALTYPE_MAIN_BG, 0, 0, ptr->HeapID );

	// -- base --
	ArcUtil_HDL_BgCharSet( ptr->arcGph, NARC_phc_diary_gra_phcdia_bg_lz_NCGR, ptr->bgl,
			BG_FRM_M_BASE, 0, 0, TRUE, ptr->HeapID );

	ArcUtil_HDL_ScrnSet( ptr->arcGph, NARC_phc_diary_gra_phcdia_bg_lz_NSCR, ptr->bgl,
			BG_FRM_M_BASE, 0, 0, TRUE, ptr->HeapID );

	// -- land --
	ArcUtil_HDL_BgCharSet( ptr->arcGph, NARC_phc_diary_gra_phcdia_bg_lz_NCGR, ptr->bgl,
			BG_FRM_M_LAND, 0, 0, TRUE, ptr->HeapID );

	ArcUtil_HDL_ScrnSet( ptr->arcGph, NARC_phc_diary_gra_phcdia_bg_a_lz_NSCR, ptr->bgl,
			BG_FRM_M_LAND, 0, 0, TRUE, ptr->HeapID );

	//=====================================================
	// Sub LCD
	//=====================================================
	// -- pal --
	ArcUtil_HDL_PalSet( ptr->arcGph, NARC_phc_diary_gra_phcdia_bg_sub_NCLR,
			PALTYPE_SUB_BG, 0, 0, ptr->HeapID );

	// -- base --
	ArcUtil_HDL_BgCharSet( ptr->arcGph, NARC_phc_diary_gra_phcdia_bg_sub_lz_NCGR, ptr->bgl,
			BG_FRM_S_BASE, 0, 0, TRUE, ptr->HeapID );

	ArcUtil_HDL_ScrnSet( ptr->arcGph, NARC_phc_diary_gra_phcdia_bg_sub_lz_NSCR, ptr->bgl,
			BG_FRM_S_BASE, 0, 0, TRUE, ptr->HeapID );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	行動時間に応じたスクリーンを展開
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	ActTime
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_LoadLandScreen( PHC_DIARY_PTR ptr, u32 hour, u32 GroundID )
{
	u8 diff = 0;

	if( hour >= 6 && hour < 16 )	{ diff = 0; } else
	if( hour >= 16 && hour < 19 )	{ diff = 1; } else
									{ diff = 2; }

	// 洞窟だったらオフセット変更
	if( GroundID == CRS_ID_CAVE )
	{
		diff += 3;
	}

	ArcUtil_HDL_ScrnSet( ptr->arcGph, NARC_phc_diary_gra_phcdia_bg_a_lz_NSCR + diff, ptr->bgl,
			BG_FRM_M_LAND, 0, 0, TRUE, ptr->HeapID );
}

//-----------------------------------------------------------------------------
/**
 *	@brief
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	GroundID
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BGM_Change( PHC_DIARY_PTR ptr, u32 GroundID )
{
	GF_ASSERT( GroundID < CRS_ID_MAX );

	HOSAKA_PRINT("set bgm by idx = %d \n",GroundID);

	Snd_BgmPlay( g_course_bgm_tbl[ GroundID ] );
}


//-----------------------------------------------------------------------------
/**
 *	@brief	OBJ初期化
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_Init( PHC_DIARY_PTR ptr )
{
	ptr->csp = CATS_AllocMemory( ptr->HeapID );
	ptr->crp = CATS_ResourceCreate( ptr->csp );

	{
		TCATS_OAM_INIT	coi = {
			0, 128,
			0, 32,
			0, 128,
			0, 32,
		};

		TCATS_CHAR_MANAGER_MAKE ccmm = {
			0,	// dummy
			1024*256,
			1024*16,
			GX_OBJVRAMMODE_CHAR_1D_256K,
			GX_OBJVRAMMODE_CHAR_1D_32K,
		};

		ccmm.num = OBJ_NUM;

		CATS_SystemInit( ptr->csp, &coi, &ccmm, 32 );
	}

	CATS_ClactSetInit( ptr->csp, ptr->crp, OBJ_NUM );

	{
		TCATS_RESOURCE_NUM_LIST crnl = { CHR_ID_MAX, PAL_ID_MAX, CEL_ID_MAX, ANM_ID_MAX, 0 };
		CATS_ResourceManagerInit( ptr->csp, ptr->crp, &crnl );
	}

	//サブサーフェースの距離を設定
	CLACT_U_SetSubSurfaceMatrix( CATS_EasyRenderGet( ptr->csp ), 0, OBJ_DISTANCE );

	GF_Disp_GX_VisibleControl(  GX_PLANEMASK_OBJ, VISIBLE_ON );		// MAIN DISP OBJ ON
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );		// SUB DISP OBJ ON

}

//-----------------------------------------------------------------------------
/**
 *	@brief	OBJ開放
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_Delete( PHC_DIARY_PTR ptr )
{
	CATS_SYS_PTR csp = ptr->csp;
	CATS_RES_PTR crp = ptr->crp;
	int i;

	PokeAct_Delete(ptr);

	for( i=0; i<CAP_ID_MAX; i++ )
	{
		GF_ASSERT( ptr->cap[i] );
		CATS_ActorPointerDelete_S( ptr->cap[i] );
	}

	CATS_ResourceDestructor_S(csp, crp);
	CATS_FreeMemory(csp);
}

//-----------------------------------------------------------------------------
/**
 *	@brief	OBJリソースロード
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_LoadRes( PHC_DIARY_PTR ptr )
{
	CATS_SYS_PTR csp = ptr->csp;
	CATS_RES_PTR crp = ptr->crp;

	// --- MAIN ---
	CATS_LoadResourcePlttArcH( csp, crp, ptr->arcGph,
			NARC_phc_diary_gra_phcdia_obj_NCLR, 0, 12, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_MAIN );

	CATS_LoadResourceCharArcH( csp, crp, ptr->arcGph,
			NARC_phc_diary_gra_phcdia_obj_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_MAIN );

	CATS_LoadResourceCellArcH( csp, crp, ptr->arcGph,
			NARC_phc_diary_gra_phcdia_obj_lz_NCER, TRUE, CEL_ID_MAIN );

	CATS_LoadResourceCellAnmArcH( csp, crp, ptr->arcGph,
			NARC_phc_diary_gra_phcdia_obj_lz_NANR, TRUE, ANM_ID_MAIN );

	// --- ICON ---
	CATS_LoadResourcePlttArcH( csp, crp, ptr->arcGph,
			NARC_phc_diary_gra_tureicon_obj_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_ICON );

	CATS_LoadResourceCharArcH( csp, crp, ptr->arcGph,
			NARC_phc_diary_gra_tureicon_obj_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_ICON );

	CATS_LoadResourceCellArcH( csp, crp, ptr->arcGph,
			NARC_phc_diary_gra_tureicon_obj_lz_NCER, TRUE, CEL_ID_ICON );

	CATS_LoadResourceCellAnmArcH( csp, crp, ptr->arcGph,
			NARC_phc_diary_gra_tureicon_obj_lz_NANR, TRUE, ANM_ID_ICON );

}

//-----------------------------------------------------------------------------
/**
 *	@brief	LCD_MAINにCAPを追加
 *
 *	@param	CATS_SYS_PTR csp
 *	@param	crp
 *	@param	pos_x
 *	@param	pos_y
 *	@param	anm
 *	@param	pri
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static CATS_ACT_PTR OBJ_AddMain( CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 pos_x, s16 pos_y, u8 anm, u8 pri )
{
	TCATS_OBJECT_ADD_PARAM_S prm = {
		0, 0, 0,
		0, 0, TCATS_ADD_S_PAL_AUTO, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_M_MAIN, PAL_ID_M_MAIN, CEL_ID_MAIN, ANM_ID_MAIN, 0, 0 }, OBJ_BGPRI, FALSE,
	};

	CATS_ACT_PTR cap;

	prm.x = pos_x;
	prm.y = pos_y;
	prm.pri = pri;
	prm.anm = anm;

	cap = CATS_ObjectAdd_S_SubDistance( csp, crp, &prm, OBJ_DISTANCE );
	CATS_ObjectAutoAnimeSetCap( cap, TRUE );

	return cap;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ICON CAPを追加
 *
 *	@param	CATS_SYS_PTR csp
 *	@param	crp
 *	@param	pos_x
 *	@param	pos_y
 *	@param	anm
 *	@param	pri
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static CATS_ACT_PTR OBJ_AddMainIcon( CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 pos_x, s16 pos_y, u8 anm, u8 pri )
{
	TCATS_OBJECT_ADD_PARAM_S prm = {
		0, 0, 0,
		0, 0, TCATS_ADD_S_PAL_AUTO, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_M_ICON, PAL_ID_M_ICON, CEL_ID_ICON, ANM_ID_ICON, 0, 0 }, OBJ_BGPRI, FALSE,
	};

	CATS_ACT_PTR cap;

	prm.x = pos_x;
	prm.y = pos_y;
	prm.pri = pri;
	prm.anm = anm;

	cap = CATS_ObjectAdd_S_SubDistance( csp, crp, &prm, OBJ_DISTANCE );
	CATS_ObjectAutoAnimeSetCap( cap, TRUE );

	return cap;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	OBJセットアップ
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_Setup( PHC_DIARY_PTR ptr )
{
	ptr->cap[ CAP_ID_UI_L ] = OBJ_AddMain( ptr->csp, ptr->crp, OBJ_UI_L_X, OBJ_UI_L_Y, NANR_phcdia_obj_yaji_l_tuch, PRI_UI );
	ptr->cap[ CAP_ID_UI_R ] = OBJ_AddMain( ptr->csp, ptr->crp, OBJ_UI_R_X, OBJ_UI_R_Y, NANR_phcdia_obj_yaji_r_tuch, PRI_UI );
	ptr->cap[ CAP_ID_UI_RET ] = OBJ_AddMain( ptr->csp, ptr->crp, OBJ_RET_X, OBJ_RET_Y, NANR_phcdia_obj_return, PRI_UI );
	ptr->cap[ CAP_ID_GROUND ] = OBJ_AddMain( ptr->csp, ptr->crp, OBJ_GROUND_X, OBJ_GROUND_Y, NANR_phcdia_obj_ground1, PRI_GROUND );
	ptr->cap[ CAP_ID_L_CMN ] = OBJ_AddMain( ptr->csp, ptr->crp, OBJ_CMN_L_X, OBJ_CMN_L_Y, NANR_phcdia_obj_takara_n, PRI_HERO );
	ptr->cap[ CAP_ID_R_CMN ] = OBJ_AddMain( ptr->csp, ptr->crp, OBJ_CMN_R_X, OBJ_CMN_R_Y, NANR_phcdia_obj_takara_n, PRI_ITEM );
	ptr->cap[ CAP_ID_L_EFF_M ] = OBJ_AddMain( ptr->csp, ptr->crp, OBJ_CMN_L_X, OBJ_EFF_S_Y, NANR_phcdia_obj_kizetsu, PRI_HERO);

	// エフェクトアイコンを読み込む
	ptr->cap[ CAP_ID_L_EFF ] = OBJ_AddMainIcon( ptr->csp, ptr->crp, OBJ_CMN_L_X, OBJ_EFF_S_Y, NANR_tureicon_obj_bikkuri, PRI_HERO);
	ptr->cap[ CAP_ID_R_EFF ] = OBJ_AddMainIcon( ptr->csp, ptr->crp, OBJ_CMN_R_X, OBJ_EFF_S_Y, NANR_tureicon_obj_bikkuri, PRI_HERO);
	ptr->cap[ CAP_ID_N_EFF ] = OBJ_AddMainIcon( ptr->csp, ptr->crp, OBJ_CMN_N_X, OBJ_EFF_S_Y, NANR_tureicon_obj_bikkuri, PRI_HERO);

	PokeAct_Init(ptr);

	// イベントで使用するOBJはOFFにしておく
	OBJ_SetEnableEventObj( ptr, FALSE );

	// 矢印OBJ表示 初期化
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_UI_L ], FALSE );
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_UI_R ], ( ptr->PageID < ptr->PageMax-1 ) );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	全てのイベント関連OBJの表示フラグを切替
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	b_enable
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_SetEnableEventObj( PHC_DIARY_PTR ptr, BOOL b_enable )
{
	PokeAct_SetEnable( &ptr->actPoke[ POKE_ACT_L ], b_enable );
	PokeAct_SetEnable( &ptr->actPoke[ POKE_ACT_R ], b_enable );
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_L_CMN ], b_enable );
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_R_CMN ], b_enable );
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_L_EFF ], b_enable );
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_L_EFF_M ], b_enable );
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_R_EFF ], b_enable );
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_N_EFF ], b_enable );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	アニメSTOP→ループ処理
 *	@note	STOPアニメの直後にループアニメがある前提
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	capID
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_OneAnime( PHC_DIARY_PTR ptr, u32 capID )
{

	if( CATS_ObjectEnableGetCap( ptr->cap[ capID ] ) &&
		CATS_ObjectAnimeActiveCheckCap( ptr->cap[ capID ] ) == FALSE )
	{
		u16 aseq = CATS_ObjectAnimeSeqGetCap( ptr->cap[ capID ] ) + 1;

		CATS_ObjectAnimeSeqSetCap( ptr->cap[ capID ], aseq );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	グラウンド変更
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	ground_idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_ChangeGround( PHC_DIARY_PTR ptr, u8 ground_idx )
{
	GF_ASSERT( ground_idx < CRS_ID_MAX );

	// グラウンド変更
	CATS_ObjectAnimeSeqCheckSetCap( ptr->cap[ CAP_ID_GROUND ], NANR_phcdia_obj_ground1 + ground_idx );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	OBJに割り当てられているキャラデータ（CGX）を書き換える
 *
 *	@param	CLACT_WORK_PTR act
 *	@param	* buf
 *	@param	siz
 *	@param	VramOfs
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_CgxChangeTransShiftVramOfs( CLACT_WORK_PTR act, u8 * buf, u32 siz, u32 VramOfs )
{
	NNSG2dImageProxy * ipc;
	u32	cgx;
	NNS_G2D_VRAM_TYPE vram_type;

	vram_type = CLACT_VramTypeGet( act );
	ipc = CLACT_ImageProxyGet( act );
	cgx = NNS_G2dGetImageLocation( ipc, vram_type );
	cgx += VramOfs;

	DC_FlushRange( buf, siz );

	switch( vram_type )
	{
		case NNS_G2D_VRAM_TYPE_2DMAIN:
			GX_LoadOBJ( buf, cgx, siz );
			break;

		case NNS_G2D_VRAM_TYPE_2DSUB:
			GXS_LoadOBJ( buf, cgx, siz );
			break;

		default : GF_ASSERT(0);
	};
}

//-----------------------------------------------------------------------------
/**
 *	@brief	連れ歩きポケモン表示用のリソースをロードするPROC
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static BOOL OBJ_LoadResPokeProc( PHC_DIARY_PTR ptr )
{
	int char_arc_idx;
	int cel_arc_idx;
	int alanm_arc_idx;
	CATS_SYS_PTR csp = ptr->csp;
	CATS_RES_PTR crp = ptr->crp;

	switch( ptr->PokeLoadProc )
	{
		case 0 :
			// Dummy Pal
			CATS_LoadResourcePlttArcH( csp, crp, ptr->arcGph,
					NARC_phc_diary_gra_phcdia_obj_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_POKE_ME );

				CATS_LoadResourcePlttArcH( csp, crp, ptr->arcGph,
					NARC_phc_diary_gra_phcdia_obj_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_POKE_YOU );

			ptr->PokeLoadProc++;
			break;

		case 1 :
			//-------------------------------------------------------------------------
			// size = 32
			//-------------------------------------------------------------------------
			{
				char_arc_idx = NARC_phc_diary_gra_poke_32k_lz_NCGR;
				cel_arc_idx = NARC_phc_diary_gra_poke_32k_lz_NCER;
				alanm_arc_idx = NARC_phc_diary_gra_poke_32k_lz_NANR;

				// CHR
				CATS_LoadResourceCharArcH( csp, crp, ptr->arcGph, char_arc_idx, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_POKE_ME_32 );
				CATS_LoadResourceCharArcH( csp, crp, ptr->arcGph, char_arc_idx, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_POKE_YOU_32 );
				// CELL
				CATS_LoadResourceCellArcH( csp, crp, ptr->arcGph, cel_arc_idx, TRUE, CEL_ID_POKE_32 );
				// ANIME
				CATS_LoadResourceCellAnmArcH( csp, crp, ptr->arcGph, alanm_arc_idx, TRUE, ANM_ID_POKE_32 );
			}
			ptr->PokeLoadProc++;
			break;

		//-------------------------------------------------------------------------
		// size = 64
		//-------------------------------------------------------------------------
		case 2 :
			{
				char_arc_idx = NARC_phc_diary_gra_poke_64k_lz_NCGR;
				cel_arc_idx = NARC_phc_diary_gra_poke_64k_lz_NCER;
				alanm_arc_idx = NARC_phc_diary_gra_poke_64k_lz_NANR;

				// CHR
				CATS_LoadResourceCharArcH( csp, crp, ptr->arcGph, char_arc_idx, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_POKE_ME_64 );
				CATS_LoadResourceCharArcH( csp, crp, ptr->arcGph, char_arc_idx, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_POKE_YOU_64 );
				// CELL
				CATS_LoadResourceCellArcH( csp, crp, ptr->arcGph, cel_arc_idx, TRUE, CEL_ID_POKE_64 );
				// ANIME
				CATS_LoadResourceCellAnmArcH( csp, crp, ptr->arcGph, alanm_arc_idx, TRUE, ANM_ID_POKE_64 );
			}
			ptr->PokeLoadProc++;
			break;

		case 3 :
			return TRUE;

		default : GF_ASSERT(0);
	}

	return FALSE;
}


//-----------------------------------------------------------------------------
/**
 *	@brief	表示切替
 *
 *	@param	PHCD_POKE_ACT_PTR poke_act
 *	@param	b_enable
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PokeAct_SetEnable( PHCD_POKE_ACT_PTR poke_act, BOOL b_enable )
{
	if( b_enable == FALSE )
	{
		// 消す時は一括
		CATS_ObjectEnableCap( poke_act->capPoke[ CAP_POKE_64 ], b_enable );
		CATS_ObjectEnableCap( poke_act->capPoke[ CAP_POKE_32 ], b_enable );
	}
	else
	{
		if( poke_act->bBigSize )
		{
			CATS_ObjectEnableCap( poke_act->capPoke[ CAP_POKE_64 ], b_enable );
		}
		else
		{
			CATS_ObjectEnableCap( poke_act->capPoke[ CAP_POKE_32 ], b_enable );
		}
	}

	// ディグダ、ダグドリオは影を出さない
	if( poke_act->MonsNo == MONSNO_DHIGUDA || poke_act->MonsNo == MONSNO_DAGUTORIO )
	{
		b_enable = FALSE;
	}

	CATS_ObjectEnableCap( poke_act->capShadow, b_enable );
}


//-----------------------------------------------------------------------------
/**
 *	@brief	アニメを設定
 *
 *	@param	PHCD_POKE_ACT_PTR poke_act
 *	@param	aseq
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PokeAct_SetAnime( PHCD_POKE_ACT_PTR poke_act, u16 aseq )
{
	// 同時に指定してしまう
	CATS_ObjectAnimeSeqCheckSetCap( poke_act->capPoke[ CAP_POKE_64 ], aseq );
	CATS_ObjectAnimeSeqCheckSetCap( poke_act->capPoke[ CAP_POKE_32 ], aseq );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	座標指定
 *
 *	@param	PHCD_POKE_ACT_PTR poke_act
 *	@param	pos_x
 *	@param	pos_y
 *	@param	b_jump
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PokeAct_SetPos( PHCD_POKE_ACT_PTR poke_act, s16 pos_x, s16 pos_y, BOOL b_jump )
{
	CATS_ObjectPosSetCap( poke_act->capPoke[ CAP_POKE_64 ], pos_x, pos_y );
	CATS_ObjectPosSetCap( poke_act->capPoke[ CAP_POKE_32 ], pos_x, pos_y );

	// ジャンプ状態のときは影を追随させない
	if( !b_jump )
	{
		CATS_ObjectPosSetCap( poke_act->capShadow, pos_x, pos_y );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケOBJ管理モジュール 生成
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PokeAct_Init( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];

	// 左側
	PokeAct_Add( &ptr->actPoke[ POKE_ACT_L ], ptr->csp, ptr->crp, OBJ_POKE_L_X, OBJ_POKE_L_Y, 0, FALSE );
	PokeAct_SetAnime( &ptr->actPoke[ POKE_ACT_L ], POKE_DIR_RIGHT );

	// 右側
	PokeAct_Add( &ptr->actPoke[ POKE_ACT_R ], ptr->csp, ptr->crp, OBJ_POKE_R_X, OBJ_POKE_R_Y, 0, TRUE );
	PokeAct_SetAnime( &ptr->actPoke[ POKE_ACT_R ], POKE_DIR_LEFT );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケOBJ管理モジュール 削除
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PokeAct_Delete( PHC_DIARY_PTR ptr )
{
	int i;
	int j;

	for( i=0; i<POKE_ACT_MAX; i++ )
	{
		for( j=0; j<CAP_POKE_MAX; j++ )
		{
			CATS_ActorPointerDelete_S( ptr->actPoke[i].capPoke[j] );
		}
		CATS_ActorPointerDelete_S( ptr->actPoke[i].capShadow );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケOBJ追加
 *
 *	@param	CATS_SYS_PTR csp
 *	@param	crp
 *	@param	pos_x
 *	@param	pos_y
 *	@param	anm
 *	@param	b_you
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PokeAct_Add( PHCD_POKE_ACT_PTR outAct, CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 pos_x, s16 pos_y, u8 anm, BOOL b_you )
{
	TCATS_OBJECT_ADD_PARAM_S prm = {
		0, 0, 0,
		0, 0, TCATS_ADD_S_PAL_AUTO, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ 0, 0, 0, 0, 0, 0 }, OBJ_BGPRI, FALSE,
	};

	int i;

	for( i=0; i<2; i++ )
	{

		prm.x = pos_x;
		prm.y = pos_y;
		prm.pri = PRI_POKE;
		prm.anm = anm;

		prm.id[0] = CHR_ID_M_POKE_ME_32 + b_you + i * 2;
		prm.id[1] = PAL_ID_M_POKE_ME + b_you;
		prm.id[2] = CEL_ID_POKE_32 + i;
		prm.id[3] = ANM_ID_POKE_32 + i;

		outAct->capPoke[i] = CATS_ObjectAdd_S_SubDistance( csp, crp, &prm, OBJ_DISTANCE );
		CATS_ObjectAutoAnimeSetCap( outAct->capPoke[i], TRUE );
		CATS_ObjectEnableCap( outAct->capPoke[i], FALSE );
	}

	// 影ロード
	outAct->capShadow = OBJ_AddMain( csp, crp, pos_x, pos_y, NANR_phcdia_obj_shadow, PRI_SHADOW );
}


//@@@ 後ほど、正式な構造体が切られる予定
typedef struct
{
	u8 FootType;
	u8 BigSize;
	u8 FlyFlg;
	u8 RoomFlg;
}DEBUG_POKE_INFO;

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケモンのグラフィックを転送/表示(内部処理)
 *
 *	@param	PHCD_POKE_ACT_PTR actPoke
 *	@param	MonsNo
 *	@param	Form
 *	@param	Sex
 *	@param	Rare
 *	@param	HeapID
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PokeAct_TransSetCore( PHCD_POKE_ACT_PTR actPoke, u16 MonsNo, u8 Form, u8 Sex, u8 Rare, HEAPID HeapID )
{
	enum { POKE_PLTT_SIZE = 16*2 };

	int i;
	ARCHANDLE* arc;
	void* pFile;
	NNSG3dResTex* pTex;
	int trans_size;
	u8 size_w, size_h;
	CLACT_WORK_PTR act;

	// アーカイブから画像サイズを取得
	{
		s16 px, py;
		DEBUG_POKE_INFO debug_info;
		int info_idx = PairPokeIdx_GetIdx( MonsNo );

		ArchiveDataLoad(&debug_info, ARC_PAIR_POKE_INFO, info_idx);

		// サイズからトランスサイズ、対象アクターを決定
		if( debug_info.BigSize )
		{
			act = actPoke->capPoke[ CAP_POKE_64 ]->act;
			trans_size = 64 * 64 / 2;
			size_w = 8;
			size_h = 8;

			actPoke->bBigSize = TRUE;

			CATS_ObjectPosGetCap( actPoke->capPoke[ CAP_POKE_64 ], &px, &py );
			CATS_ObjectPosSetCap( actPoke->capShadow, px, py );
		}
		else
		{
			act = actPoke->capPoke[ CAP_POKE_32 ]->act;
			trans_size = 32 * 32 / 2;
			size_w = 4;
			size_h = 4;

			actPoke->bBigSize = FALSE;
			CATS_ObjectPosGetCap( actPoke->capPoke[ CAP_POKE_32 ], &px, &py );
			CATS_ObjectPosSetCap( actPoke->capShadow, px, py );
		}
	}

	// データ保持
	actPoke->MonsNo = MonsNo;

	// マップモデルのアーカイブオープン
	arc = ArchiveDataHandleOpen( ARC_MMODEL, HeapID );

	// キャラ転送
	{
		int arc_idx;
		u8 *pStart;
		void* pRawData;
		void* pCharTempBuff;

		// フォルムチェック
		if( PokeFuseiFormNoCheck( MonsNo, Form ) == FALSE )
		{
			// 金銀に存在しないフォルムの場合、デフォルトフォルムを表示
			Form = 0;
		}

		//アーカイブインデックス取得
		arc_idx = GetMonsArcIdx(MonsNo, Form, Sex);
		//連れ歩きポケモンのテクスチャを読み込んでくる
		pFile = ArchiveDataLoadAllocByHandle( arc, arc_idx, HeapID );
		// テクスチャファイルを取得
		pTex = NNS_G3dGetTex( (NNSG3dResFileHeader*)pFile );

		// テクスチャロウデータ取得
		pStart = (u8*)pTex + pTex->texInfo.ofsTex;
		HOSAKA_PRINT("texsize= %x\n", pTex->texInfo.sizeTex );

		// キャラ保持用テンポラリバッファを生成
		pCharTempBuff = sys_AllocMemoryLo( HeapID, trans_size );

		for( i=0; i<8; i++ )
		{
			pRawData = &pStart[ trans_size * i ];

			ChangesInto_RawData_1D_from_2D( pRawData, size_w, 0, 0, size_w, size_h, pCharTempBuff );

			OBJ_CgxChangeTransShiftVramOfs( act, pCharTempBuff, trans_size, trans_size*i );
		}

		sys_FreeMemoryEz( pCharTempBuff );
	}

	// パレット転送
	{
		NNSG2dImagePaletteProxy* ipp;
		NNS_G2D_VRAM_TYPE type;
		u32 vram;
		u8* pStart;

		type = CLACT_VramTypeGet(act);
		pStart = (u8*)pTex + pTex->plttInfo.ofsPlttData;
		// レアだったらオフセット変更
		if( Rare )
		{
			pStart = &pStart[ POKE_PLTT_SIZE ];
		}

		DC_FlushRange( pStart, POKE_PLTT_SIZE );

		ipp = CLACT_PaletteProxyGet(act);
		vram = NNS_G2dGetImagePaletteLocation( ipp, NNS_G2D_VRAM_TYPE_2DMAIN );

		GX_LoadOBJPltt( pStart, vram, POKE_PLTT_SIZE );
	}

	// 開放処理
	sys_FreeMemoryEz( pFile );
	ArchiveDataHandleClose( arc );

	// 表示
	CATS_ObjectEnable( act, TRUE );

	// 影
	{
		BOOL bShadowEnable = TRUE;

		// ディグダ、ダグドリオは影を出さない
		if( actPoke->MonsNo == MONSNO_DHIGUDA || actPoke->MonsNo == MONSNO_DAGUTORIO )
		{
			bShadowEnable = FALSE;
		}

		CATS_ObjectEnableCap( actPoke->capShadow, bShadowEnable );
	}

}

//-----------------------------------------------------------------------------
/**
 *	@brief	現在のページのポケモンのグラフィックを転送/表示
 *
 *	@param	PHCD_POKE_ACT_PTR ptr
 *	@param	pokeID
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PokeAct_TransPage( PHC_DIARY_PTR ptr, u32 pokeActID, BOOL b_mine )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];

	// 座標をデフォルト値に
	if( pokeActID == POKE_ACT_L )
	{
		PokeAct_SetPos( &ptr->actPoke[ POKE_ACT_L ], OBJ_POKE_L_X, OBJ_POKE_L_Y, FALSE );
		PokeAct_SetAnime( &ptr->actPoke[ POKE_ACT_L ], POKE_DIR_RIGHT );
	}
	else
	{
		PokeAct_SetPos( &ptr->actPoke[ POKE_ACT_R ], OBJ_POKE_R_X, OBJ_POKE_R_Y, FALSE );
		PokeAct_SetAnime( &ptr->actPoke[ POKE_ACT_R ], POKE_DIR_LEFT );
	}

	if( b_mine )
	{
		PokeAct_TransSetCore( &ptr->actPoke[ pokeActID ],
				pPHCD->pokeNumber, pPHCD->myFolm, pPHCD->mySex, GetRare(pPHCD, TRUE), ptr->HeapID );
	}
	else
	{
		PokeAct_TransSetCore( &ptr->actPoke[ pokeActID ],
				pPHCD->enemyNumber, pPHCD->yourFolm, pPHCD->yourSex, GetRare(pPHCD, FALSE), ptr->HeapID );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	トレーナーアニメを設定
 *
 *	@param	CATS_ACT_PTR cap
 *	@param	TrSex
 *	@param	dir
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void Hero_SetAnime( CATS_ACT_PTR cap, u8 TrSex, HERO_DIR dir )
{
	u32 aseq;

	aseq = NANR_phcdia_obj_hero_l + dir;

	// 女性
	if( TrSex == PM_FEMALE )
	{
		aseq += 4;
	}

	CATS_ObjectEnableCap( cap, TRUE );
	CATS_ObjectAnimeSeqSetCap( cap, aseq );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケモンの頭上にエモーション表示
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	pokeActID
 *	@param	capID
 *	@param	aseq
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void IconAct_SetupByPoke( PHC_DIARY_PTR ptr, u32 pokeActID, u32 capID, u32 aseq )
{
	s16 px, py;

	CATS_ObjectPosGetCap( ptr->cap[ capID ], &px, &py );

	// ポケモンの大きさに合わせて座標を調整
	if( ptr->actPoke[ pokeActID ].bBigSize )
	{
		py = OBJ_EFF_L_Y;
	}
	else
	{
		py = OBJ_EFF_S_Y;
	}

	CATS_ObjectPosSetCap( ptr->cap[ capID ], px, py );
	CATS_ObjectAnimeSeqSetCap( ptr->cap[ capID ], aseq );
	CATS_ObjectEnableCap( ptr->cap[ capID ], TRUE );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	特殊アニメ管理 終了
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void SpecialAnime_Cnt_End( PHC_DIARY_PTR ptr )
{
	SpecialAnime_AwayEnd(ptr);
	SpecialAnime_PokeGetEnd(ptr);
}

//-----------------------------------------------------------------------------
/**
 *	@brief	特殊アニメ管理 ループ処理
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void SpecialAnime_Cnt_Proc( PHC_DIARY_PTR ptr )
{
	SpecialAnime_AwayProc( ptr );
	SpecialAnime_PokeGetProc( ptr );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	特殊アニメ 逃げるアニメ開始
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void SpecialAnime_AwayStart( PHC_DIARY_PTR ptr )
{
	ptr->bAway = TRUE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	特殊アニメ	逃げるアニメ終了
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void SpecialAnime_AwayEnd( PHC_DIARY_PTR ptr )
{
	ptr->bAway = FALSE;
	ptr->AwayCount = 0;
	ptr->AwaySeq = 0;
	ptr->AwaySubSeq = 0;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	特殊アニメ	逃げるアニメ主処理
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void SpecialAnime_AwayProc( PHC_DIARY_PTR ptr )
{
	if( ptr->bAway )
	{
		static const s8 END_CODE = 111;
		static const s8 jumpTbl[] = { 0, 8, 14, 18, 20, 18, 14, 8, 0, END_CODE };

		switch( ptr->AwaySeq )
		{
			// ジャンプ
			case 0 :
				PokeAct_SetPos( &ptr->actPoke[ POKE_ACT_R ], OBJ_POKE_R_X, OBJ_POKE_R_Y - jumpTbl[ ptr->AwayCount ], TRUE );
				ptr->AwayCount++;
				if( jumpTbl[ ptr->AwayCount ] == END_CODE )
				{
					ptr->AwayCount = 0;
					ptr->AwaySubSeq++;

					if( ptr->AwaySubSeq >= 2 )
					{
						PokeAct_SetAnime( &ptr->actPoke[ POKE_ACT_R ], POKE_DIR_RIGHT );
						ptr->AwaySubSeq = 0;
						ptr->AwaySeq++;
					}
				}
				break;

			// 移動
			case 1 :
				{
					static const u8 AWAY_SYNC = 7;
					static const u8 AWAY_SPEED = 8;
					s16 posX = OBJ_POKE_R_X + ptr->AwayCount * AWAY_SPEED;

					ptr->AwayCount++;

					if( ptr->AwayCount >= 5 )
					{
						// 点滅して透明に見せる
						PokeAct_SetEnable( &ptr->actPoke[ POKE_ACT_R ], (ptr->AwayCount%2==1) );
					}

					if( ptr->AwayCount >= AWAY_SYNC )
					{
						PokeAct_SetEnable( &ptr->actPoke[ POKE_ACT_R ], FALSE );
						ptr->AwayCount = 0;
						ptr->AwaySeq++;
					}
					else
					{
						PokeAct_SetPos( &ptr->actPoke[ POKE_ACT_R ], posX, OBJ_POKE_R_Y, FALSE );
					}
				}
				break;


			// 待機
			case 2 :
				break;

			default : GF_ASSERT(0);
		}
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	特殊アニメ ポケトレ：捕獲 開始
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void SpecialAnime_PokeGetStart( PHC_DIARY_PTR ptr )
{
	ptr->bPokeGet = TRUE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	特殊アニメ ポケトレ：捕獲 終了
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void SpecialAnime_PokeGetEnd( PHC_DIARY_PTR ptr )
{
	ptr->bPokeGet = FALSE;
	ptr->PokeGetCount = 0;
	ptr->PokeGetSeq = 0;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	特殊アニメ ポケトレ：捕獲 主処理
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void SpecialAnime_PokeGetProc( PHC_DIARY_PTR ptr )
{
	if( ptr->bPokeGet == FALSE ){ return; }

	switch( ptr->PokeGetSeq )
	{
		case 0 :
			// 捕獲アニメ開始
			CATS_ObjectEnableCap( ptr->cap[ CAP_ID_R_CMN ], TRUE );
			CATS_ObjectAnimeSeqSetCap( ptr->cap[ CAP_ID_R_CMN ], NANR_phcdia_obj_get );
			ptr->PokeGetSeq++;
			break;
		case 1 :
			if( ptr->PokeGetCount >= 25 )
			{
				// 相手ポケを消す
				PokeAct_SetEnable( &ptr->actPoke[ POKE_ACT_R ], FALSE );

				ptr->PokeGetCount = 0;
			}
			else
			{
				ptr->PokeGetCount++;
			}
			break;
		case 2 :
				// 空処理
			break;
		default : GF_ASSERT(0);
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理 PHC通信
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_phc_comm( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	u32 std_msg = msg_d_comm_01 + 5 * ( (pPHCD->actionId-1) / 2);
	u32 msg_prm;
	u32 myStep, yourStep;
	int StepDiff;

	// 自分ポケ
	PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
	// 相手ポケ
	PokeAct_TransPage( ptr, POKE_ACT_R, FALSE );

	myStep   = pPHCD->myStepHour;
	yourStep = pPHCD->yourStepHour;
	StepDiff = MATH_IAbs( myStep - yourStep );

	HOSAKA_PRINT( "myStep:%d yourStep:%d StepDiff:%d \n",myStep, yourStep, StepDiff );

	// 奇数 -> 勝利
	if( pPHCD->actionId % 2 == 1 )
	{
		if( StepDiff >= 100 )
		{
			msg_prm = 1;
		}
		else
		{
			msg_prm = 2;
		}
	}
	// 偶数 -> 負け
	else
	{
		if( StepDiff >= 100 )
		{
			msg_prm = 4;
		}
		else
		{
			msg_prm = 3;
		}
	}

	PRINT_Flash( ptr, std_msg, std_msg + msg_prm );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理 ダウジング
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_dowsing( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	u32 msg2;

	// 自分ポケ
	PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
	// 宝アニメスタート
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_R_CMN ], TRUE );
	CATS_ObjectAnimeSeqSetCap( ptr->cap[ CAP_ID_R_CMN ], NANR_phcdia_obj_takara_n_in );

	// メッセージが4回目以降は「アイテムぶくろが　パンパンだ」
	if( ptr->DowsingLimitID > 0 && ptr->DowsingLimitID <= ptr->PageID )
	{
		msg2 = msg_d_dowsing_02;
	}
	else
	{
		u32 myStep;

		myStep = pPHCD->myStepHour;

		if( myStep >= 4000 )	{ msg2 = msg_d_walking_d_01; } else
		if( myStep >= 3000 )	{ msg2 = msg_d_walking_d_02; } else
		if( myStep >= 2000 )	{ msg2 = msg_d_walking_d_03; } else
		if( myStep >= 1000 )	{ msg2 = msg_d_walking_d_04; } else
								{ msg2 = msg_d_walking_d_05; }
	}

	PRINT_Flash( ptr, msg_d_dowsing_01, msg2 );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理	レアアイテムゲット
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_item_rare( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	u32 msg1;

	// RARE宝アニメスタート
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_R_CMN ], TRUE );
	CATS_ObjectAnimeSeqSetCap( ptr->cap[ CAP_ID_R_CMN ], NANR_phcdia_obj_takara_r_in );

	// ポケモンをつれている
	if( pPHCD->pokeNumber )
	{
		msg1 = msg_d_item_r_01;
		PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
	}
	// ポケモンをつれていない
	else
	{
		msg1 = msg_d_item_r_02;
		Hero_SetAnime( ptr->cap[ CAP_ID_L_CMN ], ptr->TrSex, HERO_DIR_RIGHT );
	}

	// 固定メッセージ
	PRINT_Flash( ptr, msg1, NULL );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理 ポケトレ
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_poke_tore( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	u32 msg1 = msg_d_poke_get_01;
	u32 msg2 = NULL;

	// 自分ポケ
	PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
	// 相手ポケ
	PokeAct_TransPage( ptr, POKE_ACT_R, FALSE );

	// メッセージが4回目以降はmsg2を「きょうは　ちょうしが　いいみたい」にする
	// 0なら無効
	if( ptr->PokeToreLimitID > 0 && ptr->PokeToreLimitID <= ptr->PageID )
	{
		msg2 = msg_d_poke_get_02;
	}
	else
	{
		u32 myStep = pPHCD->myStepHour;

		if( myStep >= 4000 )	{ msg2 = msg_d_walking_p_01; } else
		if( myStep >= 3000 )	{ msg2 = msg_d_walking_p_02; } else
		if( myStep >= 2000 )	{ msg2 = msg_d_walking_p_03; } else
		if( myStep >= 1000 )	{ msg2 = msg_d_walking_p_04; } else
								{ msg2 = msg_d_walking_p_05; }
	}

	// メッセージ更新
	PRINT_Flash( ptr, msg1, msg2 );

	SpecialAnime_PokeGetStart( ptr );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理	レアポケゲット
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_poke_rare( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	u32 msg1 = NULL;

	// ポケモンをつれている
	if( pPHCD->pokeNumber )
	{
		msg1 = msg_d_rarepoke_01;
		PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
	}
	// ポケモンをつれていない
	else
	{
		msg1 = msg_d_rarepoke_02;
		Hero_SetAnime( ptr->cap[ CAP_ID_L_CMN ], ptr->TrSex, HERO_DIR_RIGHT );
	}

	// 相手ポケ表示
	PokeAct_TransPage( ptr, POKE_ACT_R, FALSE );

	PRINT_Flash( ptr, msg1, NULL );
}


//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理	ポケトレ 逃がした
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_poke_away( PHC_DIARY_PTR ptr )
{
	PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
	PokeAct_TransPage( ptr, POKE_ACT_R, FALSE );
	// 逃げるアニメ開始
	SpecialAnime_AwayStart( ptr );
	// 固定メッセージ
	PRINT_Flash( ptr, msg_d_poke_fail_01, NULL );
}


//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理	ポケトレ 負けた
 *
 *	@param	ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_poke_lost(PHC_DIARY_PTR ptr )
{
	PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
	PokeAct_TransPage( ptr, POKE_ACT_R, FALSE );

	// 混乱エモーション（左）
	IconAct_SetupByPoke( ptr, POKE_ACT_L, CAP_ID_L_EFF_M, NANR_phcdia_obj_kizetsu );

	// 固定メッセージ
	PRINT_Flash( ptr, msg_d_poke_fail_02, NULL );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理	イベント：アイテム入手
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_ev_item( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	u32 msg2 = NULL;

	// 自分のポケモン表示
	PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
	// 宝
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_R_CMN ], TRUE );
	CATS_ObjectAnimeSeqSetCap( ptr->cap[ CAP_ID_R_CMN ], NANR_phcdia_obj_takara_n );

	if ( pPHCD->friendly >= 250 )	{ msg2 = msg_d_event_item_02; } else
	if ( pPHCD->friendly >= 200 )	{ msg2 = msg_d_event_item_03; } else
	if ( pPHCD->friendly >= 150 )	{ msg2 = msg_d_event_item_04; } else
	if ( pPHCD->friendly >= 90 )	{ msg2 = msg_d_event_item_05; }

	PRINT_Flash( ptr, msg_d_event_item_01, msg2 );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理	イベント：ワット入手
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_ev_watt( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	u32 param = pPHCD->actionId - ACT_ID_EV_WATT_IN;
	int friendly = pPHCD->friendly;
	u32 msg1;

	msg1 = msg_d_event_01_01 + (param*3);

	if( friendly >= 200 )	{ msg1 += 0; } else
	if( friendly >= 60 )	{ msg1 += 1; } else
	if( friendly >= 0 )		{ msg1 += 2; }

	// ACT_ID_EV_WATT_IN で msg_d_event_01_03 が呼ばれることはありえないが、
	// データ破壊などによって参照された場合は強制的に msg_d_event_01_02 で上書きを行なう
	if( msg1 == msg_d_event_01_03 )
	{
		msg1 = msg_d_event_01_02;
	}

	// 自分ポケ
	PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
	// 主人公
	Hero_SetAnime( ptr->cap[ CAP_ID_R_CMN ], ptr->TrSex, HERO_DIR_LEFT );

	PRINT_Flash( ptr, msg1, NULL );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理	つれてけ
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_tureteke( PHC_DIARY_PTR ptr )
{
	// 自分のポケモン表示
	PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
	// 主人公表示
	Hero_SetAnime( ptr->cap[ CAP_ID_R_CMN ], ptr->TrSex, HERO_DIR_RIGHT );
	// びっくりエモーション(右)
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_R_EFF ], TRUE );
	CATS_ObjectAnimeSeqSetCap( ptr->cap[ CAP_ID_R_EFF ], NANR_tureicon_obj_bikkuri );
	// 固定メッセージ
	PRINT_Flash( ptr, msg_d_event_come_01, NULL );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理	強制帰宅
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_return( PHC_DIARY_PTR ptr )
{
	// 右に自分ポケ
	PokeAct_TransPage( ptr, POKE_ACT_R, TRUE );
	PokeAct_SetAnime( &ptr->actPoke[ POKE_ACT_R ], POKE_DIR_RIGHT );
	// 固定メッセージ
	PRINT_Flash( ptr, msg_d_event_back_01, NULL );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理	開始
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_act_start( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	u32 msg2;

	if( pPHCD->pokeNumber == 0 )
	{
		// ポケモンをつれていない
		msg2 = msg_diary_start_02;
	}
	else
	{
		// ポケモンをつれている
		PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
		msg2 = msg_diary_start_01;
	}

	// 主人公表示
	Hero_SetAnime( ptr->cap[ CAP_ID_R_CMN ], ptr->TrSex, HERO_DIR_RIGHT );
	// 固定メッセージ
	PRINT_Flash( ptr, msg_diary_start_time, msg2 );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理 終了
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_act_end( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	u32 msg2;
	u32 temp;
	u32 point = 0;

	// 自分ポケ
	PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
	// 主人公アニメ
	Hero_SetAnime( ptr->cap[ CAP_ID_R_CMN ], ptr->TrSex, HERO_DIR_RIGHT );

	//---------------------------------------------
	// ポイント計算
	//---------------------------------------------
	// 歩数
	temp = pPHCD->myStepDay / 100;
	point += MATH_IMin( temp , 655 );
	// 捕獲ポケモン数
	temp = ptr->PokeToreCount * 10;
	point += MATH_IMin( temp , 40 );
	// 入手アイテム数
	temp = ptr->DowsingCount * 10;
	point += MATH_IMin( temp , 40 );
	// 通信回数
	temp = ptr->CommCount * 15;
	point += MATH_IMin( temp , 150 );
	// レアポケ
	point += ptr->bGetRarePoke * 250;
	// レアアイテム
	point += ptr->bGetRareItem * 250;

	if( point >= 550 )	{ msg2 = msg_diary_rslt_01; } else
	if( point >= 300 )	{ msg2 = msg_diary_rslt_02; } else
	if( point >= 200 )	{ msg2 = msg_diary_rslt_03; } else
	if( point >= 150 )	{ msg2 = msg_diary_rslt_04; } else
	if( point >= 100 )	{ msg2 = msg_diary_rslt_05; } else
	if( point >= 30 )	{ msg2 = msg_diary_rslt_06; } else
						{ msg2 = msg_diary_rslt_07; }

	PRINT_Flash( ptr, msg_diary_end_time, msg2 );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理　歩数表示
 *
 *	@param	PHC_DIARY_PTR ptr
 *	@param	hour
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_step( PHC_DIARY_PTR ptr, u32 hour )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	u32 myStep = pPHCD->myStepHour; //GetStepDay( pPHCD->myStepDay );
	u32 msg1 = NULL;

	// 通常レイアウト
	if( myStep >= 300 )
	{
		PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
		Hero_SetAnime( ptr->cap[ CAP_ID_R_CMN ], ptr->TrSex, HERO_DIR_RIGHT );

		if( myStep >= 4000 )	{ msg1 = msg_d_walking_01; } else
		if( myStep >= 2000 )	{ msg1 = msg_d_walking_02; } else
		if( myStep >= 1000 )	{ msg1 = msg_d_walking_03; } else
								{ msg1 = msg_d_walking_04; }
	}
	// 特殊レイアウト
	else
	{
		PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );
		PokeAct_SetPos( &ptr->actPoke[ POKE_ACT_L ], OBJ_POKE_N_X, OBJ_POKE_N_Y, FALSE );
		PokeAct_SetAnime( &ptr->actPoke[ POKE_ACT_L ], POKE_DIR_LEFT_STOP );

		// 睡眠エモーション(中央)
		IconAct_SetupByPoke( ptr, POKE_ACT_L, CAP_ID_N_EFF, NANR_tureicon_obj_nemui );

		if( ( hour >= 20 && hour <= 24 ) || ( hour >= 0 && hour <= 7 ) )
		{
			msg1 = msg_diary_rest_01;
		}
		else if( hour >= 12 && hour <= 16 )
		{
			msg1 = msg_diary_rest_02;
		}
		else
		{
			msg1 = msg_diary_rest_03;
		}
	}

	PRINT_Flash( ptr, msg1, NULL );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ処理　未来処理
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void page_future( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	u32 msg1 = msg_d_comm_next_01;

	// 自分ポケ
	PokeAct_TransPage( ptr, POKE_ACT_L, TRUE );

	// 相手ポケ(思い出せないので煙)
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_R_CMN ], TRUE );
	CATS_ObjectAnimeSeqSetCap( ptr->cap[ CAP_ID_R_CMN ], NANR_phcdia_obj_smoke );
	// 例外的に影だけ表示
	CATS_ObjectEnableCap( ptr->actPoke[ POKE_ACT_R ].capShadow, TRUE );
	// ？アイコン
	CATS_ObjectEnableCap( ptr->cap[ CAP_ID_R_EFF ], TRUE );
	CATS_ObjectAnimeSeqSetCap( ptr->cap[ CAP_ID_R_EFF ], NANR_tureicon_obj_gimon );

	PRINT_Flash( ptr, msg1, NULL );
}



//-----------------------------------------------------------------------------
/**
 *	@brief	ページ読み込み処理
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void Page_Load( PHC_DIARY_PTR ptr )
{
	PHCDiary* pPHCD = ptr->pDiary[ ptr->PageID ];
	int hour;

	HOSAKA_PRINT("*** PageID : %d actID : %d ***\n", ptr->PageID, pPHCD->actionId);

	//このページの時間を計算・保持
	Page_CalcDate( ptr );

	// 時間を取得
	hour = ptr->PageTime.hour;

	// 時間帯とコースによってBGを変更
	BG_LoadLandScreen( ptr, hour, GetGroundID(pPHCD) );
	// コースによって地面プレートを変更
	OBJ_ChangeGround( ptr, GetGroundID( pPHCD ) );

	// コースが変わっていたらBGMを変更
	if( ptr->CourseIDPre != pPHCD->courseId )
	{
		BGM_Change( ptr, GetGroundID( pPHCD ) );
	}

	// コースIDを保持
	ptr->CourseIDPre = pPHCD->courseId;

	//=======================================================================================
	// 行動ID判定
	//=======================================================================================
	// PHC通信
	if( pPHCD->actionId >= ACT_ID_COMM_IN && pPHCD->actionId <= ACT_ID_COMM_END )
	{
		if( pPHCD->romVersion == VERSION_GOLD || pPHCD->romVersion == VERSION_SILVER )
		{
			// 通常
			page_phc_comm( ptr );
		}
		else
		{
			// 未来のポケモン
			page_future( ptr );
		}
	}
	// ダウジング
	else if( pPHCD->actionId == ACT_ID_DOWSING )
	{
		page_dowsing( ptr );
	}
	// 配布アイテム入手
	else if( pPHCD->actionId == ACT_ID_ITEM_RARE )
	{
		page_item_rare( ptr );
	}
	// ポケトレ
	else if( pPHCD->actionId == ACT_ID_POKETORE )
	{
		page_poke_tore( ptr );
	}
	// レアポケゲット
	else if( pPHCD->actionId == ACT_ID_POKE_RARE )
	{
		page_poke_rare( ptr );
	}
	// ポケトレ：逃げた
	else if( pPHCD->actionId == ACT_ID_POKE_TORE_AWAY )
	{
		page_poke_away( ptr );
	}
	// ポケトレ：負けた
	else if( pPHCD->actionId == ACT_ID_POKE_TORE_FAIL )
	{
		page_poke_lost( ptr );
	}
	// イベント：アイテム入手
	else if( pPHCD->actionId == ACT_ID_EV_ITEM )
	{
		page_ev_item( ptr );
	}
	// イベント：ワット開始
	else if( pPHCD->actionId >= ACT_ID_EV_WATT_IN && pPHCD->actionId <= ACT_ID_EV_WATT_END )
	{
		page_ev_watt( ptr );
	}
	// つれてけ
	else if( pPHCD->actionId == ACT_ID_TURETEKE )
	{
		page_tureteke( ptr );
	}
	// 強制帰宅
	else if( pPHCD->actionId == ACT_ID_POKE_RETURN )
	{
		page_return( ptr );
	}
	// 開始
	else if( pPHCD->actionId == ACT_ID_ACT_START )
	{
		page_act_start( ptr );
	}
	// 終了
	else if( pPHCD->actionId == ACT_ID_ACT_END )
	{
		page_act_end( ptr );
	}
	// 歩数変化
	else if( pPHCD->actionId == ACT_ID_STEP )
	{
		page_step( ptr, hour );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ読み込みリクエスト発行
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void Page_LoadReq( PHC_DIARY_PTR ptr )
{
	// ページ読み込み開始フラグON
	ptr->bPageLoad = TRUE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ページ読み込みシーケンス処理
 *
 *	@param	PHC_DIARY_PTR ptr
 *
 *	@retval TRUE:処理終了
 */
//-----------------------------------------------------------------------------
static BOOL Page_LoadProc( PHC_DIARY_PTR ptr )
{
	// 既に読み込みが終わっていたらTRUE
	if( ptr->bPageLoad == FALSE )
	{
		return TRUE;
	}

	switch( ptr->PageLoadProc )
	{
		case 0 :
			// ワイプ開始
			WIPE_SYS_Start( WIPE_PATTERN_M, WIPE_TYPE_FADEOUT, WIPE_TYPE_FADEOUT,
							WIPE_FADE_WHITE, 2, 1, ptr->HeapID );

			ptr->PageLoadProc++;
			break;

		case 1 :
			if( WIPE_SYS_EndCheck() )
			{
				// 矢印OBJ表示切替
				CATS_ObjectEnableCap( ptr->cap[ CAP_ID_UI_L ], ( ptr->PageID > 0 ) );
				// 矢印OBJ表示切替
				CATS_ObjectEnableCap( ptr->cap[ CAP_ID_UI_R ], ( ptr->PageID < ptr->PageMax-1 ) );
				// 一旦描画フラグをOFF
				OBJ_SetEnableEventObj( ptr, FALSE );
				// 特殊アニメ終了
				SpecialAnime_Cnt_End( ptr );

				// ページロード
				Page_Load( ptr );

				// ワイプ開始
				WIPE_SYS_Start( WIPE_PATTERN_M, WIPE_TYPE_FADEIN, WIPE_TYPE_FADEIN,
								WIPE_FADE_WHITE, 2, 1, ptr->HeapID );

				ptr->PageLoadProc++;
			}
			break;

		case 2 :
			if( WIPE_SYS_EndCheck() )
			{
				ptr->PageLoadProc = 0;
				ptr->bPageLoad = FALSE;
				return TRUE;
			}
			break;

		default : GF_ASSERT(0);
	}

	return FALSE;
}

//=============================================================================
/**
 *								外部公開関数
 */
//=============================================================================


//-----------------------------------------------------------------------------
/**
 *	@brief	モジュール初期化処理
 *
 *	@param	PROC* proc
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PHC_DIA_Create( PROC* proc )
{
	PHC_DIARY_PTR ptr;
	const PHC_DIARY_PARAM* inParam;

	inParam = (PHC_DIARY_PARAM*)PROC_GetParentWork(proc);

#if DEBUG_ONLY_FOR_genya_hosaka
#if 0
	// @@@
	// セット関数のテスト
	{
		PHC_DIARY_PARAM* inParam_t = (PHC_DIARY_PARAM*)PROC_GetParentWork(proc);
		PHC_END_PAGE_DATA data = {0};
		static const STRCODE MyNick[] = { TA_, MA_, NE_, GI_, EOM_, };

		data.p_myNickName = MyNick;
		data.pokeNumber = 151;
		data.myFolm = 0;
		data.mySex = 0;
		data.myRareColor = 0;
		data.myStepDay = 600;

		PhcDiary_SetEndPage( &inParam_t->pDiaryData[23], &data );
	}
#endif
#endif // DEBUG_ONLY_FOR_genya_hosaka

	GF_ASSERT(inParam);

	// ヒープ生成
	sys_CreateHeap( HEAPID_BASE_APP, HEAPID_PHC_DIARY, PHC_DIA_HEAP_SIZE );

	ptr = PROC_AllocWork( proc, sizeof(PHC_DIARY), HEAPID_PHC_DIARY );
	MI_CpuClear8( ptr, sizeof(PHC_DIARY) );

	// メンバ初期化
	ptr->HeapID = HEAPID_PHC_DIARY;
	ptr->inParam = inParam;

	// データ取得・生成
	DATA_Setup(ptr);

	// DISP/VRAM 初期化
	VramDispInit();
	SetVramBank();

	//下画面をメインにする
	sys.disp3DSW = DISP_3D_TO_SUB;
	GF_Disp_DispSelect();

	// アーカイブ展開
	ptr->arcGph = ArchiveDataHandleOpen( ARC_PHC_DIARY_GRA, ptr->HeapID );

	// システム初期化
	BG_Init(ptr);
	BMPWIN_Init(ptr);
	OBJ_Init(ptr);

	// Message
	WIPE_ResetWndMask( WIPE_DISP_MAIN );
	WIPE_ResetWndMask( WIPE_DISP_SUB );

	sys_VBlankFuncChange( PHC_DIA_VBlank, ptr );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	モジュール終了処理
 *
 *	@param	PROC* proc
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PHC_DIA_Delete( PROC* proc )
{
	PHC_DIARY_PTR ptr = PROC_GetWork(proc);

	BMPWIN_Delete(ptr);
	BG_Delete(ptr);
	OBJ_Delete(ptr);

	ArchiveDataHandleClose( ptr->arcGph );

	// 上下画面を元に戻しておく
	sys.disp3DSW = DISP_3D_TO_MAIN;
	GF_Disp_DispSelect();

	VramDispInit();

	PROC_FreeWork(proc);
	sys_DeleteHeap(HEAPID_PHC_DIARY);
}

//-----------------------------------------------------------------------------
/**
 *	@brief	VBLANK関数
 *
 *	@param	void* work
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PHC_DIA_VBlank( void* work )
{
	PHC_DIARY_PTR ptr = work;

	GF_ASSERT( ptr );

	GF_ASSERT( ptr->crp );
	GF_ASSERT( ptr->bgl );

	CATS_Draw( ptr->crp );
	CATS_RenderOamTrans();

	GF_BGL_VBlankFunc( ptr->bgl );

	OS_SetIrqCheckFlag( OS_IE_V_BLANK );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	PHC日記 初期化
 *
 *	@param	PROC* proc
 *	@param	seq
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
PROC_RESULT PhcDiaryProc_Init( PROC* proc, int* seq )
{
	PHC_DIARY_PTR ptr = PROC_GetWork(proc);

	switch( *seq )
	{
		case 0 :
			PHC_DIA_Create( proc );
			(*seq)++;
			break;
		case 1 :
			// 汎用リソースロード
			BG_LoadRes(ptr);
			OBJ_LoadRes(ptr);
			(*seq)++;
			break;
		case 2 :
			// OBJ Poke
			// データが大きいので分割読み込み
			if(	OBJ_LoadResPokeProc(ptr) )
			{
				OBJ_Setup(ptr);
				PRINT_Static(ptr);
				ptr->CourseIDPre = 0xff; // 初回ＢＧＭ読み込み
				Page_Load(ptr);
				(*seq)++;
			}
			break;
		case 3 :
			// ワイプ開始
			WIPE_SYS_Start( WIPE_PATTERN_WMS, WIPE_TYPE_FADEIN, WIPE_TYPE_FADEIN,
						WIPE_FADE_WHITE, WIPE_DEF_DIV, WIPE_DEF_SYNC, ptr->HeapID );
			(*seq)++;
			break;
		case 4:
			if( WIPE_SYS_EndCheck() )
			{
				HOSAKA_PRINT("Proc Init Finish\n");
				return PROC_RES_FINISH;
			}
			break;

		default : GF_ASSERT(0);
	}

	return PROC_RES_CONTINUE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	PHC日記 終了
 *
 *	@param	PROC* proc
 *	@param	seq
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
PROC_RESULT PhcDiaryProc_End( PROC* proc, int* seq )
{
	PHC_DIARY_PTR ptr = PROC_GetWork(proc);

	switch( *seq )
	{
		// アニメ終了待ち
		case 0:
			if( CATS_ObjectAnimeActiveCheckCap( ptr->cap[ CAP_ID_UI_RET ] ) == FALSE )
			{
				(*seq)++;
			}
			break;

		case 1:
			WIPE_SYS_Start( WIPE_PATTERN_WMS, WIPE_TYPE_FADEOUT, WIPE_TYPE_FADEOUT,
							WIPE_FADE_BLACK, WIPE_DEF_DIV, WIPE_DEF_SYNC, ptr->HeapID );
			(*seq)++;
			break;

		case 2:
			if( WIPE_SYS_EndCheck() )
			{
				PHC_DIA_Delete( proc );
				HOSAKA_PRINT("Proc End Finish\n");
				return PROC_RES_FINISH;
			}
			break;

		default : GF_ASSERT(0);
	}

	return PROC_RES_CONTINUE;
}


//-----------------------------------------------------------------------------
/**
 *	@brief	PHC日記 主処理
 *
 *	@param	PROC* proc
 *	@param	seq
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
PROC_RESULT PhcDiaryProc_Main( PROC* proc, int* seq )
{
	PHC_DIARY_PTR ptr = PROC_GetWork(proc);

#ifdef PM_DEBUG
	// デバッグボタンを押すたびにＢＧＭ切替
	{
		static u8 ground_idx = 0;
		if( sys.trg & PAD_BUTTON_DEBUG )
		{
			HOSAKA_PRINT("bgm load Ground ID: %d \n", ground_idx);
			BGM_Change( ptr, ground_idx );
			ground_idx = (ground_idx+1) % CRS_ID_MAX;
		}
	}
#endif

	if( Page_LoadProc( ptr ) == FALSE )
	{
		// ページ読み込み中は他の処理を行わない
		return PROC_RES_CONTINUE;
	}

	// ページ移動処理
	if( CheckLeft(ptr) )
	{
		// ページ切替
		if( ptr->PageID > 0 ){ ptr->PageID--; }
		// ページ読み込みフラグON
		Page_LoadReq( ptr );
		// 選択音
		Snd_SePlay( SEQ_SE_DP_SELECT );
	}
	else if( CheckRight(ptr) )
	{
		// ページ切替
		ptr->PageID = (ptr->PageID+1) % ptr->PageMax;
		// ページ読み込みフラグON
		Page_LoadReq( ptr );
		// 選択音
		Snd_SePlay( SEQ_SE_DP_SELECT );
	}
	else if( CheckReturn( ptr ) )
	{
		return PROC_RES_FINISH;
	}

	// 特殊アニメ処理
	SpecialAnime_Cnt_Proc( ptr );

	// アニメSTOP→ループ処理
	OBJ_OneAnime( ptr, CAP_ID_R_CMN );
	OBJ_OneAnime( ptr, CAP_ID_L_EFF );
	OBJ_OneAnime( ptr, CAP_ID_R_EFF );
	OBJ_OneAnime( ptr, CAP_ID_N_EFF );

	return PROC_RES_CONTINUE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	最終ページのセット関数
 *
 *	@param	outDiary	セットするページへのポインタ
 *	@param	inData		最終ページ設定用のデータ
 *
 *	@retval	none
 */
//-----------------------------------------------------------------------------
void PhcDiary_SetEndPage( PHCDiary* outDiary, const PHC_END_PAGE_DATA* inData )
{
	int i;

	// 設定する日記領域を念のためクリア
	MI_CpuClear8( outDiary, sizeof(PHCDiary) );

	// ニックネームをコピー
	MI_CpuCopy8( inData->p_myNickName, outDiary->myNickname, sizeof(STRCODE)*PHCD_NICKNAME_SIZE );

	outDiary->pokeNumber	= inData->pokeNumber;
	outDiary->myFolm		= inData->myFolm;
	outDiary->mySex			= inData->mySex;
	outDiary->myRareColor	= inData->myRareColor;

	// 歩数をコピー
//	outDiary->myStepDay[0] = inData->myStepDay&0xff;
//	outDiary->myStepDay[1] = (inData->myStepDay>>8)&0xff;
//	outDiary->myStepDay[2] = (inData->myStepDay>>16)&0xff;
	outDiary->myStepDay = inData->myStepDay;

	outDiary->actionId		= ACT_ID_ACT_END;
	outDiary->rtcSecond		= 0xffffffff;		// ダミー値：絶対最後に来るようにする
}

//-----------------------------------------------------------------------------
/**
 *	@brief	配布ポケモンページ用のデータ設定関数（ページ必要情報だけ上書き）
 *
 *	@param	PHCDiary* DiaryHeadPtr				日記情報の先頭ポインタ
 *	@param	PHC_SHARE_POKE_PAGE_DATA* inDiary	配布ポケモンページに上書きするデータ
 *
 *	@retval	none
 */
//-----------------------------------------------------------------------------
void  PhcDiary_SetSharePokePage( PHCDiary* DiaryHeadPtr, const PHC_SHARE_POKE_PAGE_DATA* inData )
{
	int i;

	for( i=0; i<PHC_DIA_DATA_MAX; i++ )
	{
		PHCDiary* setDiary = &DiaryHeadPtr[i];

		if( setDiary->actionId == ACT_ID_SHARE_POKE )
		{
			setDiary->enemyNumber	= inData->enemyNumber;
			setDiary->yourFolm		= inData->yourFolm;
			setDiary->yourSex		= inData->yourSex;
			setDiary->yourRareColor	= inData->yourRareColor;
		}
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	配布ウポケモンページの存在チェック関数
 *
 *	@param	PHCDiary* DiaryHeadPtr				日記情報の先頭ポインタ
 *
 *	@retval	TRUE:配布ポケモンページが存在する
 */
//-----------------------------------------------------------------------------
BOOL  PhcDiary_CheckSharePokePage( PHCDiary* DiaryHeadPtr )
{
	int i;

	for( i=0; i<PHC_DIA_DATA_MAX; i++ )
	{
		PHCDiary* setDiary = &DiaryHeadPtr[i];

		if( setDiary->actionId == ACT_ID_SHARE_POKE )
		{
			return TRUE;
		}
	}

	return FALSE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	エラーページの存在チェック
 *
 *	@param	PhcDiary* DiaryHeadPtr		日記情報の先頭ポインタ
 *
 *	@retval	TRUE:エラーページあり
 */
//-----------------------------------------------------------------------------
BOOL PhcDiary_CheckErrorPage( PHCDiary* DiaryHeadPtr )
{
	int i;

	for( i=0; i<PHC_DIA_DATA_MAX; i++ )
	{
		PHCDiary* inPHCD = &DiaryHeadPtr[i];

#ifdef DEBUG_ONLY_FOR_genya_hosaka
		// デバッグボタン押しっぱなしで不正日記があったことにする
		if( sys.cont & PAD_BUTTON_DEBUG )
		{
			return TRUE;
		}
#endif

		// actionIdが0クリアされている場合は破損扱いにはしない（アプリ内部でactionId=0のページは飛ばされる）
		if( inPHCD->actionId == ACT_ID_NULL )
		{
			continue;
		}

		// actionIdの範囲オーバーは破損とみなす
		if( inPHCD->actionId >= ACT_ID_MAX )
		{
			return TRUE;
		}

		// 自分のポケモンNoが0だったら破損とみなす
		if( inPHCD->pokeNumber == 0 )
		{
			return TRUE;
		}

		// 金銀VERの場合、ポケモンNOが金銀で出現する範囲外だったら破損とみなす
		if( inPHCD->romVersion == VERSION_GOLD || inPHCD->romVersion == VERSION_SILVER )
		{
			if( inPHCD->pokeNumber > MONSNO_END || inPHCD->enemyNumber > MONSNO_END )
			{
				return TRUE;
			}
		}

		// コースIDがMAXより大きい場合破損とみなす（8以上）
		if( inPHCD->courseId >= CRS_ID_MAX )
		{
			return TRUE;
		}
	}

	return FALSE;
}
